Author | Message |
---|---|
apolinarsanchez
Posts: 8
|
Posted 22:31 Oct 06, 2019 |
I get the following exception when trying to persist a computer science Department object after setting Department.id = 1: Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: lab2.model.Department at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154) at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:181) at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:188) at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:795) at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:773) at lab2.main.Lab2.main(Lab2.java:56)....
When I instead insert the users, department, and search into the database using mysql, I get the following exception when querying for department with id = 1: Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.type.SerializationException: could not deserialize at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154) at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1534) at org.hibernate.query.internal.AbstractProducedQuery.getSingleResult(AbstractProducedQuery.java:1573) at lab2.main.Lab2.main(Lab2.java:65)... When I google these exceptions most of the results point to the annotations. My only guess is that it may be because of the annotations for Department.searches and Search.department. Heres how I annotated them: @OneToMany(mappedBy = "department") @OrderBy( "createdOn asc" ) private List<Search> searches;
@ManyToOne private Department department;
Does anybody have any idea what may be causing this?
|
apolinarsanchez
Posts: 8
|
Posted 01:40 Oct 07, 2019 |
Figured it out. It was my annotation for Department.chairperson. |