Annotation « Data Type « JPA Q&A

1. How is a blob column annotated in Hibernate?

How is a blob column annotated in Hibernate? So far I have a class that has:

@Column( name = "FILEIMAGE" )
private byte[ ] fileimage ;
public byte[ ] getFileimage ( ) { return this.fileimage ...

2. Text Field using Hibernate Annotation

I am having trouble setting the type of a String, it goes like

public void setTextDesc(String textDesc) {
 this.textDesc = textDesc;

public String getTextDesc() {
 return textDesc;
and it didn't work, I checked the ...

3. hard time setting autogenerated time with hibernate JPA annotations

thanks to you guys my knowlegde on hibernate has been improve dratiscally. now i hit a block here about current_timestamp. here is my codes

@Column(name="DATE_CREATED", insertable=false, updatable=false, columnDefinition="timestamp default current_timestamp")
private Date dateCreated;

@Column(name="LAST_MODIFIED", insertable=false, ...

4. Why does JPA have a @Transient annotation?

Java has the transientkeyword. Why does JPA have @Transient instead of simply using the already existing java keyword?

5. Hibernate with Annotations and MySQL: Creation Date

I try to save the date of creation of my entity. I have found that approach. I tried to implement it but the date doesn't reach my db-table.

import java.util.Date;

import ...

6. What's the JDO equivalent of the JPA @PersistenceContext annotation

In JPA, you can inject an EntityManager with the @PersistenceContext annotation:

private EntityManager entityManager;
What is the JDO equivalent of this for a PersistenceManager?
private PersistenceManager persistenceManager;

7. Is it possible to do type conversion (from boolean to yes_no) in pure JPA?

There is an annotation in Hibernate that can persist boolean types as 'Y'/'N' in the database. an-instead-of-0-1 However if I don't want to bind to Hibernate is there a way to ...

8. Is there a "collection-type" equivalent annotation in Hibernate?

In Hibernate you can define a custom collection type by setting the "collection-type" attribute in hibernate xml mapping file. I was wondering if there is an annotation equivalent. PS: I tried using @Type ...

9. assign timestamp in jpa annotation

is there a way to automatically assing a timestamp value in a Date variable on a enity EJB? here is how my enity looks like.

package com.jr.entities;

import java.util.Date;

import javax.persistence.Column;

public class TransactionDAO {


10. Is there an equivalent annotation for OnDelete in JPA2

import org.hibernate.annotations.OnDelete;

@OnDelete(action = org.hibernate.annotations.OnDeleteAction.CASCADE)
List<Foo> foos;
Is there an equivalent JPA2 annotation for the Hibernate annotation OnDelete?

11. Problem with JPA Annotation @Transient

I'm trying to mapping a data base from "Drupal" with Hibernate and JPA to make a Java layer for work with the data. In a class, I need to add an attribute, ...

12. Hibernate - How to set sql-type by annotation?

I have a file as a byte[] fileContent. My mySql-scheme is generated by Hibernate and by default hibernate sets the sql-type of fileContent to BLOB. But a BLOB is not big enough ...

13. JPA, transient annotation not overwriting OneToOne?

I have a superclass Product and a subclass Reduction. Now I want the subclass to override a property of the superclass so it isn't persisted in the database. I excpeted it ...

14. Annotation @Basic to transient variables

I am having a POJO class which consists of:
- persistent properties,
- transient properties. While writing HQL I considered both: persistent and transient properties. I.e. HQL like select persistent_properties,transient_prop from Pojo_classname is it correct? Can I ...

16. Enums and AttributeOverrides annotation

Hi all, Is there any way to store String presentation of Enum to db when using the AttributeOverrides annotation. The idea what i would like to do as code: Code: @Embeddable public class FooEnum { public enum MyEnum { VALUE1, VALUE2 }; private Date start; private Date end; private MyEnum myEnum; ...

17. String variable with Range annotation

Hi I have a String variable It is nullable=true in the database. I have defined it as follows : @Column(name = "MINI_NO", length = 1) @Range(min = 1, max = 6, message = "miniNo out of Range") public String getMiniNo() { return this.miniNo; } public void setMiniNo(String miniNo) { this.miniNo = miniNo; } The thing is when I am updating this ...

18. Hibernate annotations and automatic Timestamp

With insertable = false in your column annotation you removed the column from any insert statement. I only use this annotation, when I want to provide a second field for the identifier of a reference. So both fields references the same column like @Column(insertable=false, updateable=false ...) private Long roleId; @ManyToMany(...) private Role role; Kind regards Michael

19. annotation needed to handle Set emailAddresses

20. Problem with JPA Annotation @Transient

I'm trying to mapping a data base from "Drupal" with Hibernate and JPA to make a Java layer for work with the data. In a class, I need to add an attribute, called "rank" to use it later, but that attribute doesn't exist in the database, so I put @Transient annotation... I use the set method to put a value on ...

21. Way to specify column data type using EJB 3.0 annotations?

Hibernate version: hibernate-3.0beta1 with hibernate-annotations-3.0alpha1 I found that I was able to specify the data type for a column using the following EJB 3.0 annotation. @Column(columnDefinition="TEXT") This works great. However, I'm wondering if there is a way to specify the type in a DBMS-independent fashion. For example, if I use the annotation above, it will work with MySQL and with Microsoft ...

22. Hibernate 3.0.5 + annotations + java 5.0 Enums problem

Hibernate version: 3.0.5 Full stack trace of any exception that occurs: org.hibernate.exception.GenericJDBCException: could not insert: [com.mgjug.model.persistence.usuario.Usuario] at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException( at org.hibernate.exception.ErrorCodeConverter.convert( at org.hibernate.exception.JDBCExceptionHelper.convert( at org.hibernate.persister.entity.BasicEntityPersister.insert( at org.hibernate.persister.entity.BasicEntityPersister.insert( at org.hibernate.action.EntityIdentityInsertAction.execute( at org.hibernate.engine.ActionQueue.execute( at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate( at org.hibernate.event.def.AbstractSaveEventListener.performSave( at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId( at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId( at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient( at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate( at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate( at org.hibernate.impl.SessionImpl.saveOrUpdate( at org.hibernate.impl.SessionImpl.saveOrUpdate( at com.mgjug.eai.HibernateGenericDAO.insert( at at at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at ...

23. property-ref equivalent with annotations

Hi guys, I'm a little new to Hibernate, so thought I would try testing my knowledge by moving some of the hibernate mappings from hb.xml files to java annotations. I am stuck on one issue, where I want to create a many-to-one relationship from one class, Trade, to another Instrument. However, I don't want to reference the primary key, but a ...

24. How to config enum with annotation as the *EnumUserType do?

Newbie Joined: Thu Nov 13, 2008 3:57 am Posts: 3 Need help with Hibernate? Read this first: ... AskForHelp It's easy to customize the persistence of enum by using *EnumUserType. But how to achieve the save effect with annotation? For example, I have a enum like this: Code: public enum OrderType { RecOrder, ...

25. Minimising annotations on UserType properties

Hello, I have created several UserType classes for my domain model custom value types. I have defined them in a file using @TypeDef annotations (wrapped inside @TypeDefs). Then in my domain model classes, I annotate each such property with @Type. It is also necessary to include @Column so that the schema generator shows the correct type length (e.g. 'CHAR(10)') in ...