-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Collection is not associated with any seesion
PostPosted: Wed Nov 17, 2010 2:11 pm 
Newbie

Joined: Wed Oct 20, 2010 11:22 am
Posts: 14
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!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.