views:

5

answers:

0

I have an entity bean which is made using Hibernate annotation.

@Entity  
@org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)  
@Table(name="[tbDDE]")  
public class DElement implements Serializable{  

@Column(name = "[ID]", nullable = false, unique=true, updatable=false, insertable=false)  
@GeneratedValue(strategy=GenerationType.AUTO)  
private Integer id;  

@Id  
@Column(name = "[DAElementID]", unique = true, nullable = false)  
   private String dElementId;  
}  

DAElementID is String type and is a primary key while id is column which is having value autogenerated.

so, whenever I save the particular POJO, it's get saved into the table properly. Here id is Autogenerated value and dElementId is Primary key. now, once I save and then my next statement is to try to load the particular entity from DB, i get value of id as null but do get proper value of dElementId.

i.e my saving and retrieving is from the same method.

Now, my question is why I am getting null value for id column though it has proper value in table. I am commiting the transaction as well as flushing the transaction too, but did not help. Remember as soon as I save the object, I am trying to retrieve the object, because I need id value.