开发者

java hibernate eclipse xml

I got the answers from u all regarding the previous topic that was use of hibern开发者_如何学JAVAate 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???????


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.


just add transient keyword in declaration

For Example

private transient Image thumbnailImage;


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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜