I have a spring mvc application running on glassfish. I don't know the source of my problem so ill elaborate as much as possible. I have 2 Classes
A User Class
@Entity
@Table(name="Users")
public class User extends BaseEntity<User> {
// other fields
@OneToMany(fetch = FetchType.EAGER, mappedBy = "user")
@OrderBy(value = "id DESC")
private Set<OtherClass> objs;
// getters and setters
}
and an OtherClass:
@Entity
@Table(name="OtherObjects")
public class OtheClass extends BaseEntity<OtheClass> {
// other fields
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "User", nullable = false)
private User user;
// getters and setters
}
i retrieve a user object when the application starts and put it in the session object. while runtime, the user can add to the DB a "OtherClass" object. the otherClass object is saved correctly in the DB (with a relation to the correct user row in the Users table). the thing is that after the user added the otherClass object at runtime, the Set of other objects doesn't update. the weirder thing is that even if i retrieve the user object from the DB again, i don't get the updated Set of OtherClass. This is my persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="myPU" transaction-type="JTA">
<jta-data-source>jdbc/MyDataSource</jta-data-source>
<class>org.company.entities.OtherClass</class>
<class>org.company.entities.User</class>
<exclude-unlisted-classes />
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.current_session_context_class" value="thread" />
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider" />
<property name="hibernate.hbm2ddl.auto" value="create" />
</properties>
</persistence-unit>
</persistence>
I recently changed my transaction manager from the jpa transaction manager of spring to JTA transaction manager. (i suppose it has something to do with it). Any ideas? if further code or configuration is required, please tell and i'll post an update.