Ars
Ars

Reputation: 59

java hibernate eclipse xml

I got the answers from u all regarding the previous topic that was use of hibernate with table not having any primary key, but i have one question that can we use transient keyword prefixed to ID variable in the entity class so that not to persist that value into database???????

Upvotes: 0

Views: 95

Answers (3)

Nikunj
Nikunj

Reputation: 3128

Same answer again.

If the ID is not stored in database, then how it will identify an unique row?
In your case, the prmiary key will be null or empty. If a primary key can be null?

I think you should take any auto increment ID as primary key. It should not affect your database design.

Upvotes: 0

JB Nizet
JB Nizet

Reputation: 691635

No. You must have a persistent ID in all your Hibernate entities. The transient keyword is used to avoid serializing it when transferring the object to another JVM (or to a file). The @Transient annotation is used to mark a field not persistent, but it can't be used for the ID, which is absolutely necessary in order to use Hibernate.

Upvotes: 1

Jigar Joshi
Jigar Joshi

Reputation: 240860

just add transient keyword in declaration

For Example

private transient Image thumbnailImage;

Upvotes: 0

Related Questions