[英]May I need avoid composition without annotations with Hibernate and MySQL?
In my project which is based on Hibernate
and MySQL
I'm using barcode so I have set primary key
to bracode
as well as id
field and since there's composition it's problematic that occurring : 在我的基于
Hibernate
和MySQL
项目中,我使用条形码,因此我将primary key
设置为bracode
以及id
字段,并且由于存在这种组合,因此出现问题是有问题的:
org.hibernate.id.IdentifierGenerationException: null id generated for:class com.pojo.MyClass
org.hibernate.id.IdentifierGenerationException:为以下类生成空ID:com.pojo.MyClass类
So I'm not using @annotations 所以我不使用@annotations
I've checked without composition and just make barcode unique rather set primary key
so would this approach could be cause of any future problem in my project? 我检查了没有成分,只是使条形码唯一,而是设置了
primary key
所以这种方法可能会导致我的项目将来出现任何问题吗?
If the barcode for you entity is unique identifier just put @Id annotation on this field and put the unique constrain in the data base for that field as well. 如果您实体的条形码是唯一标识符,只需在该字段上添加@Id注释,并将唯一约束也放入该字段的数据库中。 If you are using several fields as unique constrain in this case you should use composite key.
如果在这种情况下使用多个字段作为唯一约束,则应使用复合键。 If I get you question right.
如果我明白你的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.