Unable to configure EntityManagerFactory - No identifier specified for entity - exception
in case if class has no getter
------------------------------------------------------------------------------------------------------------------------
Key: EJB-440
URL:
http://opensource.atlassian.com/projects/hibernate/browse/EJB-440
Project: Hibernate Entity Manager
Issue Type: Improvement
Components: EntityManager
Reporter: Vitali Yemialyanchyk
Priority: Minor
Attachments: screenshot-1.jpg
I'm start to use hibernate/jpa. I get the following problem:
orm.xml:
===== BEGIN ===
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
http://java.sun.com/xml/ns/persistence/orm_1_0.xsd">
<!-- entity class="TestIdClass" access="FIELD" -->
<entity class="TestIdClass">
<attributes >
<id name="testId">
<generated-value strategy="IDENTITY"/>
</id>
</attributes>
</entity>
</entity-mappings>
===== END ===
TestIdClass.java:
===== BEGIN ===
public class TestIdClass {
public Integer testId;
//public Integer getTestId() {
//return testId;
//}
public void setTestId(Integer testId) {
this.testId = testId;
}
}
===== END ===
test function:
===== BEGIN ===
static public void testJPA() {
configuration = new Ejb3Configuration();
Map map = null;
String str = null;
// here error - without getter ->
// javax.persistence.PersistenceException: [PersistenceUnit: TestHibId] Unable to
configure EntityManagerFactory
configuration = configuration.configure(str, map);
hibernateConfig = configuration.getHibernateConfiguration();
// here error - without setter ->
// org.hibernate.PropertyNotFoundException: Could not find a setter for property testId in
class TestIdClass
sessionFactory = hibernateConfig.buildSessionFactory();
}
===== END ===
if getTestId - getter commented I get exception. As I think I spend too much time to find
what was a reason of the problem:
access="FIELD" - resolve the problem, but this solution isn't so obvious,
especially if stack trace exception says:
===
Unable to configure EntityManagerFactory
org.hibernate.AnnotationException: No identifier specified for entity: TestIdClass
===
for me it looks weird - cause I was strongly believe what I specify id here!
It will be nice I hibernate throws more information with the error or even suggestion to
check access value...
I use latest versions of hibernate jars.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira