Mandatory setter for primary key in Hibernate with hbm.xml

Hispurvissord

New Member
Is it possible to avoid setter for primary key with Hibernate XML mapping configuration? When annotations are used you don't have to have setter method declared. See example. I'm using Hibernate version 4.1.2.[*]XML based configuration\[code\]public class Entity { private Integer id; public Integer getId() { return id; }}<class name="Language" table="language"> <id name="id" column="id"> <generator class="native" /> </id></class>\[/code\]While initializing Hibernate exception is thrown\[code\]Caused by: org.hibernate.PropertyNotFoundException: Could not find a setter for property id in class net.kreuzman.eshop.core.domain.l10n.Language at org.hibernate.property.BasicPropertyAccessor.createSetter(BasicPropertyAccessor.java:252) at org.hibernate.property.BasicPropertyAccessor.getSetter(BasicPropertyAccessor.java:245) at org.hibernate.mapping.Property.getSetter(Property.java:325) at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertySetter(PojoEntityTuplizer.java:444) at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:182) at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:82)... 49 more\[/code\][*]Annotation based configuration\[code\]@Entity@Table(name="entity")public class Entity { @Id @Column(name="id") @GeneratedValue(strategy=GenerationType.AUTO) private Integer id; public Integer getId() { return id; }}\[/code\]This works well.
 
Back
Top