I am trying to
I am having a problem with @ElementCollections when I deploy to tomcat. When I run under eclipse w/o tomcat, there is no problem, I get the elements back. But when I move to tomcat, it throws an error.
The element in my java entity file is:
Code:
@ElementCollection(fetch=FetchType.EAGER)
@Column(name="description",updatable=false,insertable=false)
@CollectionTable(name="flds", joinColumns=
{@JoinColumn(name="type", referencedColumnName="fld_type"),
@JoinColumn(name="delim", referencedColumnName="delimiter")})
private List<String> descriptions;
This is my defined resource in "tomcat/conf/context.xml".
Code:
<Resource name="app1/DB" auth="Container"
type="javax.sql.DataSource"
driverClassName="com.informix.jdbc.IfxDriver"
username="usr1" password="usr1"
url="jdbc:informix-sqli://us:9999/mydb:INFORMIXSERVER=testtcp1;dbdate=MDY4"
validationQuery="select first 1 type from animals"
defaultAutoCommit="false"
maxActive="10" maxIdle="5" maxWait="1000"
removeAbandoned="true" removeAbandonedTimeout="300" logAbandoned="true"/>
This is my persistence.xml file:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="HibernateTest" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>jpa.common.Class1</class>
<properties>
<property name="hibernate.connection.datasource" value="app1/DB" />
</properties>
</persistence-unit>
</persistence>
This is the java class that will call everything
Code:
public class MyService
{
public static EntityManagerFactory emf = Persistence.createEntityManagerFactory("HibernateTest");
public static EntityManager em;
public List<Class1> getClass1(int type)
{
em = emf.createEntityManager();
em.getTransaction().begin();
String classQuery="select c from Class1 c where c.type = :type";
Query q = em.createQuery(classQuery);
q.setParameter("type", type);
@SuppressWarnings("unchecked")
List<Class1> classs = q.getResultList();
}
And this is the error I'm getting:
Code:
PersistenceException : org.hibernate.HibernateException: collection is not associated with any session"
I did not include the entire java entity class. Just the element that I'm having problems with.
Again, it works when I run on my machine through eclipse (I change the persistence.xml file for a direct connect). When I move to tomcat (I change persistence.xml to use DataSource), that's when I get the error!
Any help would be great!