Re: Problem with JpaTest in JPA 2.0 tutorial

136 views
Skip to first unread message

Lars Vogel

unread,
Apr 26, 2013, 10:04:34 AM4/26/13
to vog...@googlegroups.com
Same answer, I haven't really looked at that code for a while and plan to do this somewhere in the future.




2013/4/17 ejs <edse...@gmail.com>
Hello Lars,

I'm new to JPA and to persistence in general (other than basic JDBC, which I have used a bit). My target persistence implementation is Hibernate + MySQL, so I am trying to run your JPA 2.0 tutorial using Hibernate + MySQL instead of EclipseLink + derby. I was able to do this successfully with this tutorial's Main class after making minor adjustments to the persistence.xml file. However, when I run the JUnit test class (JpaTest) I get the following Hibernate errors related to column mapping:

JpaTest
de.vogella.jpa.hibernate.main.JpaTest
checkFamily(de.vogella.jpa.hibernate.main.JpaTest)
javax.persistence.PersistenceException: [PersistenceUnit: people] Unable to build EntityManagerFactory
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890)
        at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:57)
(etc)

Caused by: org.hibernate.MappingException: Could not determine type for: de.vogella.jpa.hibernate.model.Family, at table: Person, for columns: [org.hibernate.mapping.Column(family)]
        at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:314)
        at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:292)
        at org.hibernate.mapping.Property.isValid(Property.java:239)
(etc)


deletePerson(de.vogella.jpa.hibernate.main.JpaTest)
javax.persistence.PersistenceException: [PersistenceUnit: people] Unable to build EntityManagerFactory
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890)
        at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:57)
(etc)

Caused by: org.hibernate.MappingException: Could not determine type for: de.vogella.jpa.hibernate.model.Family, at table: Person, for columns: [org.hibernate.mapping.Column(family)]
        at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:314)
        at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:292)
        at org.hibernate.mapping.Property.isValid(Property.java:239)
(etc)

checkAvailablePeople(de.vogella.jpa.hibernate.main.JpaTest)
javax.persistence.PersistenceException: [PersistenceUnit: people] Unable to build EntityManagerFactory
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890)
        at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:57)
(etc)

Caused by: org.hibernate.MappingException: Could not determine type for: de.vogella.jpa.hibernate.model.Family, at table: Person, for columns: [org.hibernate.mapping.Column(family)]
        at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:314)
        at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:292)
        at org.hibernate.mapping.Property.isValid(Property.java:239)
(etc)

Of note:

- These all essentially the same error, encountered in each of the different @Test methods.

- I made the same changes to the persistence.xml file in the project for JpaTest that I made (and used successfully) in the project for the Main class. These changes consist of setting the driver and url to values that work for MySQL, as well as the ddl property, for which I used:
          <property name="hibernate.hbm2ddl.auto" value="create" />
These changed worked as expected for the Main part of this tutorial.

- I'm using Hibernate 4.1.11 (Final)

- The Eclipse development environment is Eclipse Java EE IDE for Web Developers (Juno Service Release 2).

- The Runtime JRE is JavaSE-1.7 (jre7).

- Test runner is JUnit 4.

Things I'm wondering about:

- I have been assuming that the code in this tutorial is fully JPA 2.0 compliant, and that it's based on a subset of JPA 2.0 that's fully implemented by both EclipseLink and Hibernate. Might that be a bad assumption?

- Might these errors be due to the versions of Hibernate and Java that I'm using? When the tutorial was developed, earlier versions (Hibernate 3.x instead of 4.x and jre6 rather than jre7) were widely used, so I'm wondering if I'm encountering an incompatibility that's due to these recent major version updates.

Thank you in advance for your help!

--Ed

--
You received this message because you are subscribed to the Google Groups "vogella" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vogella+u...@googlegroups.com.
To post to this group, send email to vog...@googlegroups.com.
Visit this group at http://groups.google.com/group/vogella?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.



Message has been deleted

ejs

unread,
Apr 26, 2013, 11:47:20 AM4/26/13
to vog...@googlegroups.com
When you do, perhaps it will be useful to consider the changes I needed to make for Hibernate:

In class Person,
- I had to change the type of id (and the get/Set methods for this field) from String to long.
- I had to move the @ManyToOne annotation from the method getFamily() to the field family, and
  the @OneToMany annotation from getJobList to jobList.

I don't know if these are problems with the code. I suspect that they are supposed to work according to the standard; however, they did not.

Also,to avoid a compiler warning I removed the following line from deletePerson():
     Person person = (Person) q.getSingleResult();
because person was not used anywhere.

--Ed
Reply all
Reply to author
Forward
0 new messages