-->
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.  [ 7 posts ] 
Author Message
 Post subject: could not initialize proxy - the owning Session was closed
PostPosted: Fri Aug 11, 2006 2:38 pm 
Newbie

Joined: Fri Aug 11, 2006 2:30 pm
Posts: 3
Hibernate version:
3.0
Code between sessionFactory.openSession() and session.close():
springframewok
Name and version of the database you are using:
postgresql 8.0
Hi
I am new in spring and hibernate, every thing works fine until I start with one-to-one relation, my unit tests start to failed, i think that I need change something in *.hbm.xml file but I try different options but didn't get satisfied result. Here is my error message during performing unit test:
Code:
Hibernate: insert into members (address_id, contact_id, member_id) values (?, ?, ?)
Hibernate: update addresses set city=?, state=?, zip=?, country=?, phone=?, fax=? where address_id=?
2006-08-11 19:40:26 org.hibernate.LazyInitializationException <init>
SEVERE: could not initialize proxy - the owning Session was closed
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
   at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:53)
   at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84)
   at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134)
   at org.noip.jorg.pms.manager.AddressImpl$$EnhancerByCGLIB$$30e7c4a8.toString(<generated>)
   at java.lang.String.valueOf(String.java:2577)
   at java.lang.StringBuffer.append(StringBuffer.java:220)
   at junit.framework.Assert.format(Assert.java:289)
   at junit.framework.Assert.failNotEquals(Assert.java:282)
   at junit.framework.Assert.assertEquals(Assert.java:64)
   at junit.framework.Assert.assertEquals(Assert.java:71)
   at org.noip.jorg.pms.manager.AddressImplTest.testSave(AddressImplTest.java:77)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at junit.framework.TestCase.runTest(TestCase.java:154)
   at junit.framework.TestCase.runBare(TestCase.java:127)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


My address.java
Code:
@Configurable("templateAddress")
public class AddressImpl implements Address {
    private Integer id;
    private String city;
    private String state;
    private String zip;
    private String country;
    private String phone;
    private String fax;
    private static AddressDao dao;
    private Member member;
   
    public void save(){
        dao.save(this);
    }
   
    public void delete(){
        dao.delete(this);
    }

    public AddressDao getDao() {
        return dao;
    }

    public void setDao(AddressDao dao) {
        this.dao = dao;
    }
//setters and getters
   
}


My Address.hbm.xml

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sf.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
   <class name="org.noip.jorg.pms.manager.AddressImpl" table="addresses" lazy="true">
      <id name="id" column="address_id" type="java.lang.Integer" unsaved-value="0">
         <generator class="native"></generator>
      </id>
      <property name="city" column="city" type="java.lang.String"></property>
      <property name="state" column="state" type="java.lang.String"></property>
      <property name="zip" column="zip" type="java.lang.String"></property>
      <property name="country" column="country" type="java.lang.String"></property>
      <property name="phone" column="phone" type="java.lang.String"></property>
      <property name="fax" column="fax" type="java.lang.String"></property>
      <one-to-one name="member" class="org.noip.jorg.pms.manager.MemberImpl" property-ref="address"></one-to-one>
      <one-to-one name="customer" class="org.noip.jorg.pms.manager.CustomerImpl" property-ref="address"></one-to-one>
   </class>
</hibernate-mapping>   
   

My MemberImpl.java

Code:

@Configurable("templateMember")
public class MemberImpl implements Member {
    private Integer id;
    private Contact contact;
    private Address address;
    private static MemberDao dao;
    private Set<Task> tasks = new TreeSet<Task>();
    private Set<Group> groups = new HashSet<Group>();
   
    public void addToGroup(Group group){
        if(group == null)
            throw new InvalidAttributeValueException("Group can't be null");
        if(groups.contains(group))
            throw new InvalidAttributeValueException("User already belongs to this group");
        this.groups.add(group);
    }
   
    public void removeFromGroup(Group group){
        if(group == null)
            throw new InvalidAttributeValueException("Null group!!");
        if(!groups.contains(group))
            throw new InvalidAttributeValueException("Member don't belong to this group!!");
        this.groups.remove(group);
    }
   
    public void save(){
        dao.save(this);
    }
   
    public void delete(){
        dao.delete(this);
    }

    public  MemberDao getDao() {
        return dao;
    }

    public void setDao(MemberDao dao) {
        this.dao = dao;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    public Contact getContact() {
        return contact;
    }

    public void setContact(Contact contact) {
        this.contact = contact;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Set<Task> getTasks() {
        return tasks;
    }

    public void setTasks(Set<Task> tasks) {
        this.tasks = tasks;
    }

    public Set<Group> getGroups() {
        return groups;
    }

    public void setGroups(Set<Group> groups) {
        this.groups = groups;
    }
   
}




[B} MemberImpl.hbm.xml
[/B]
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sf.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
   <class name="org.noip.jorg.pms.manager.MemberImpl" table="members">
      <id name="id" column="member_id" type="java.lang.Integer" unsaved-value="0">
         <generator class="native"></generator>
      </id>
      <set name="groups" table="members_groups">
         <key column="member_id"></key>
         <many-to-many column="group_id" class="org.noip.jorg.pms.manager.GroupImpl"></many-to-many>
      </set>
      <many-to-one name="address" class="org.noip.jorg.pms.manager.AddressImpl" column="address_id" unique="true" cascade="save-update"></many-to-one>
      <many-to-one name="contact" class="org.noip.jorg.pms.manager.ContactImpl" column="contact_id" unique="true" cascade="save-update"></many-to-one>
      <set name="tasks" table="members_tasks">
         <key column="member_id"></key>
         <many-to-many column="task_id" class="org.noip.jorg.pms.project.Task"></many-to-many>
      </set>
   </class>
</hibernate-mapping>


AddressImplTest.java where I get error message

Code:
package org.noip.jorg.pms.manager;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import junit.framework.TestCase;

public class AddressImplTest extends TestCase {
    public static ClassPathXmlApplicationContext appContext = null;
    private Address address, address1, address2;
    private Members members;
    private Member member, member1, member2;
   
    protected void setUp() throws Exception {
        if (appContext == null)
            appContext = new ClassPathXmlApplicationContext("dataAccessContext.xml");
       
       
        members = new MembersImpl();
        members.deleteAll();
       
        member = members.create();
        member1 = members.create();
        member2 = members.create();
       
       
        address = new AddressImpl();
        address.setCity("Rydułtowy");
        address.setCountry("Poland");
        address.setFax("032-45678");
        address.setPhone("032-4568-767");
        address.setState("Sląskie");
        address.setZip("44-280");
        address.save();
       
        address1 = new AddressImpl();
        address1.setCity("Rybnik");
        address1.setCountry("Poland");
        address1.setFax("032-49678");
        address1.setPhone("032-4968-767");
        address1.setState("Sląskie");
        address1.setZip("44-220");
        address1.save();
       
        address2 = new AddressImpl();
        address2.setCity("Essen");
        address2.setCountry("Deutschland");
        address2.setFax("0048-49678");
        address2.setPhone("0048-4968-767");
        address2.setState("Essen Ost");
        address2.setZip("22-333");
        address2.save();
       
       
       
        member.setAddress(address);
        address.setMember(member);
        address.save();
        member.save();
       
        member1.setAddress(address1);
        address1.setMember(member1);
        address1.save();
        member1.save();
       
        member2.setAddress(address2);
        address2.setMember(member2);
        address2.save();
        member2.save();
       

    }

    /*
     * Test method for 'org.noip.jorg.pms.manager.AddressImpl.save()'
     */
    public void testSave() {
        assertEquals(member.getAddress(), members.find(member.getId()).getAddress());
        assertEquals(member1.getAddress(), members.find(member1.getId()).getAddress());
        assertEquals(member2.getAddress(), members.find(member2.getId()).getAddress());
    }

    /*
     * Test method for 'orgname.noip.jorg.pms.manager.AddressImpl.delete()'
     */
    public void testDelete() {
        address.delete();
        assertEquals(null, members.find(member.getId()).getAddress());
        address1.delete();
        assertEquals(null, members.find(member1.getId()).getAddress());
        address2.delete();
        assertEquals(null, members.find(member2.getId()).getAddress());
    }

}

this code is a part of project management system for student organization develop by students http://www.aegee.gliwice.pl/jorg/, i will be thankfully for any response


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 11, 2006 3:36 pm 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
Can you please post your dataAccessContext.xml file so I can see how your beans are weaved together?


Top
 Profile  
 
 Post subject: dataAccessContex.xml
PostPosted: Fri Aug 11, 2006 3:59 pm 
Newbie

Joined: Fri Aug 11, 2006 2:30 pm
Posts: 3
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
   <bean class="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect" factory-method="aspectOf"/>
   
   <bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
      <property name="location"><value>/WEB-INF/jdbc.test.properties</value></property>
   </bean>
   
   <bean id="pmsFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
      depends-on="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect">
      <property name="dataSource">
         <ref local="dataSource"/>
   </property>
   
      <property name="mappingResources">
         <list>
         <!-- start package org.noip.jorg.pms.calendar.* -->
            <value>org/noip/jorg/pms/calendar/dao/Entry.hbm.xml</value>
            <value>org/noip/jorg/pms/calendar/dao/Calendar.hbm.xml</value>
            <value>org/noip/jorg/pms/project/dao/Project.hbm.xml</value>
             <value>org/noip/jorg/pms/project/dao/Task.hbm.xml</value> 
             <value>org/noip/jorg/pms/project/dao/Resource.hbm.xml</value>
         <!-- stop package org.noip.jorg.pms.calendar.* -->
         <!-- start package org.noip.jorg.pms.manager.* -->
            <value>org/noip/jorg/pms/manager/dao/Member.hbm.xml</value>
            <value>org/noip/jorg/pms/manager/dao/Group.hbm.xml</value>
            <value>org/noip/jorg/pms/manager/dao/Address.hbm.xml</value>
            <value>org/noip/jorg/pms/manager/dao/Contact.hbm.xml</value>
            <value>org/noip/jorg/pms/manager/dao/Customer.hbm.xml</value>
         <!-- stop package org.noip.jorg.pms.manager.* -->       
             <value>org/noip/jorg/security/dao/Login.hbm.xml</value>
            <value>org/noip/jorg/security/dao/Role.hbm.xml</value>            
            <value>org/noip/jorg/security/dao/Right.hbm.xml</value>
         </list>
      </property>
      <property name="hibernateProperties">
         <props>
            <prop key="hibernate.dialect">
               org.hibernate.dialect.PostgreSQLDialect
            </prop>
            <prop key="hibernate.show_sql">
               true
            </prop>
         </props>
      </property>
   </bean>
      
   
   <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" destroy-method="close">
      <property name="driverClassName">
         <value>${jdbc.driverClassName}</value>
      </property>
      
      <property name="url">
         <value>${jdbc.url}</value>
      </property>
      
      <property name="username">
         <value>${jdbc.username}</value>
      </property>
      
      <property name="password">
         <value>${jdbc.password}</value>
      </property>
   </bean>
   
   
   <!--  start package org.noip.jorg.pms.calendar.* -->
   <bean name="templateCalendar" class="org.noip.jorg.pms.calendar.Calendar">
      <property name="dao">
         <bean class="org.noip.jorg.pms.calendar.dao.CalendarDaoHibernateImpl"
         depends-on="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect">
            <property name="sessionFactory">
               <ref local="pmsFactory" />
            </property>
         </bean>
      </property>
   </bean>
   
   <bean name="templateEntry" class="org.noip.jorg.pms.calendar.Entry">
      <property name="dao">
         <bean class="org.noip.jorg.pms.calendar.dao.EntryDaoHibernateImpl"
         depends-on="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect">
            <property name="sessionFactory">
               <ref local="pmsFactory" />
            </property>
         </bean>
      </property>
   </bean>
   
   <bean name="templateProject" class="org.noip.jorg.pms.project.ProjectImpl">
      <property name="dao">
         <bean class="org.noip.jorg.pms.project.dao.ProjectDaoHibernateImpl"
         depends-on="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect">
            <property name="sessionFactory">
               <ref local="pmsFactory" />
            </property>
         </bean>
      </property>
   </bean>
   
   <bean name="templateProjects" class="org.noip.jorg.pms.project.ProjectsImpl">
      <property name="dao">
         <bean class="org.noip.jorg.pms.project.dao.ProjectDaoHibernateImpl"
         depends-on="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect">
            <property name="sessionFactory">
               <ref local="pmsFactory" />
            </property>
         </bean>
      </property>
   </bean>
   
   <bean name="templateTask" class="org.noip.jorg.pms.project.Task">
      <property name="dao">
         <bean class="org.noip.jorg.pms.project.dao.TaskDaoHibernateImpl"
         depends-on="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect">
            <property name="sessionFactory">
               <ref local="pmsFactory" />
            </property>
         </bean>
      </property>
   </bean>
   
   <bean name="templateResource" class="org.noip.jorg.pms.project.Resource">
      <property name="dao">
         <bean class="org.noip.jorg.pms.project.dao.ResourceDaoHibernateImpl"
         depends-on="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect">
            <property name="sessionFactory">
               <ref local="pmsFactory" />
            </property>
         </bean>
      </property>
   </bean>
   <!--  stop package org.noip.jorg.pms.calendar.* -->
   
   <!--  start package org.noip.jorg.pms.manager.* -->
   <bean name="templateMembers" class="org.noip.jorg.pms.manager.MembersImpl">
      <property name="dao">
         <bean class="org.noip.jorg.pms.manager.dao.MemberDaoHibernateImpl"
         depends-on="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect">
            <property name="sessionFactory">
               <ref local="pmsFactory" />
            </property>
         </bean>
      </property>
   </bean>
   
   <bean name="templateMember" class="org.noip.jorg.pms.manager.MemberImpl">
      <property name="dao">
         <bean class="org.noip.jorg.pms.manager.dao.MemberDaoHibernateImpl"
         depends-on="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect">
            <property name="sessionFactory">
               <ref local="pmsFactory" />
            </property>
         </bean>
      </property>
   </bean>
   
   

   <bean name="templateGroups" class="org.noip.jorg.pms.manager.GroupsImpl">
      <property name="dao">
         <bean class="org.noip.jorg.pms.manager.dao.GroupDaoHibernateImpl"
         depends-on="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect">
            <property name="sessionFactory">
               <ref local="pmsFactory" />
            </property>
         </bean>
      </property>
   </bean>
   
   
   <bean name="templateGroup" class="org.noip.jorg.pms.manager.GroupImpl">
      <property name="dao">
         <bean class="org.noip.jorg.pms.manager.dao.GroupDaoHibernateImpl"
         depends-on="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect">
            <property name="sessionFactory">
               <ref local="pmsFactory" />
            </property>
         </bean>
      </property>
   </bean>
   
   <bean name="templateCustomers" class="org.noip.jorg.pms.manager.CustomersImpl">
      <property name="dao">
         <bean class="org.noip.jorg.pms.manager.dao.CustomerDaoHibernateImpl"
         depends-on="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect">
            <property name="sessionFactory">
               <ref local="pmsFactory" />
            </property>
         </bean>
      </property>
   </bean>
   
   <bean name="templateCustomer" class="org.noip.jorg.pms.manager.CustomerImpl">
      <property name="dao">
         <bean class="org.noip.jorg.pms.manager.dao.CustomerDaoHibernateImpl"
         depends-on="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect">
            <property name="sessionFactory">
               <ref local="pmsFactory" />
            </property>
         </bean>
      </property>
   </bean>
   
   <bean name="templateAddress" class="org.noip.jorg.pms.manager.AddressImpl">
      <property name="dao">
         <bean class="org.noip.jorg.pms.manager.dao.AddressDaoHibernateImpl"
         depends-on="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect">
            <property name="sessionFactory">
               <ref local="pmsFactory" />
            </property>
         </bean>
      </property>
   </bean>
   
   <bean name="templateContact" class="org.noip.jorg.pms.manager.ContactImpl">
      <property name="dao">
         <bean class="org.noip.jorg.pms.manager.dao.ContactDaoHibernateImpl"
         depends-on="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect">
            <property name="sessionFactory">
               <ref local="pmsFactory" />
            </property>
         </bean>
      </property>
   </bean>
   
   <!--
   <bean name="templateGroups" class="org.noip.jorg.pms.manager.GroupsImpl" lazy-init="true">
      <property name="dao">
         <ref local="groupDao" />
      </property>
   </bean>
   
   <bean id="templateGroup" class="org.noip.jorg.pms.manager.GroupImpl" lazy-init="true" >
      <property name="dao"><ref local="groupDao" /></property>
   </bean>

   <bean id="groupDao" class="org.noip.jorg.pms.manager.dao.GroupDaoHibernateImpl">
      <property name="sessionFactory">
         <ref local="pmsFactory" />
      </property>
   </bean>
    -->
   
   <!--  stop package org.noip.jorg.pms.manager.* -->   
   
   
   <bean id="loginDao" class="org.noip.jorg.security.dao.LoginDaoHibernateImpl">
      <property name="sessionFactory">
         <ref local="pmsFactory" />
      </property>
   </bean>
   
   <bean id="roleDao" class="org.noip.jorg.security.dao.RoleDaoHibernateImpl">
      <property name="sessionFactory">
         <ref local="pmsFactory" />
      </property>
   </bean>
   
   <bean id="rightDao" class="org.noip.jorg.security.dao.RightDaoHibernateImpl">
      <property name="sessionFactory">
         <ref local="pmsFactory" />
      </property>
   </bean>
   
   <bean id="templateLogin" class="org.noip.jorg.security.LoginImpl" lazy-init="true" >
      <property name="dao"><ref local="loginDao" /></property>
   </bean>
   
   <bean id="templateLogins" class="org.noip.jorg.security.LoginsImpl" lazy-init="true" >
      <property name="dao"><ref local="loginDao" /></property>
   </bean>
   
   <bean id="templateRole" class="org.noip.jorg.security.RoleImpl" lazy-init="true" >
      <property name="dao"><ref local="roleDao" /></property>
   </bean>

   <bean id="templateRoles" class="org.noip.jorg.security.RolesImpl" lazy-init="true" >
      <property name="dao"><ref local="roleDao" /></property>
   </bean>

   <bean id="templateRight" class="org.noip.jorg.security.RightImpl" lazy-init="true" >
      <property name="dao"><ref local="rightDao" /></property>
   </bean>
   
   <bean id="templateRights" class="org.noip.jorg.security.RightsImpl" lazy-init="true" >
      <property name="dao"><ref local="rightDao" /></property>
   </bean>
</beans>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 11, 2006 5:58 pm 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
Does your address class have a toString() method which is acessing the owing class or another class that is potentially lazy loaded? Post the toString() of the address class. It seems a bit odd that the session would be closed at that time, but I cannot see where the session is being obtained in the first place (aop.xml?). I use Spring2 aop namespace to inject aspects (aspectj expressions) as opposed to annotations and am less familiar with them.


Top
 Profile  
 
 Post subject: called set collection out of session
PostPosted: Sat Aug 12, 2006 7:40 am 
Newbie

Joined: Thu May 05, 2005 6:44 am
Posts: 2
I think you maybe called set collection out of session.
in spring,a hibernate style calling maybe like this:
Code:
    private List findGroupMember(final String groupid, final int startIndex,
            final int pagerecord) throws DataAccessException {
        return getHibernateTemplate().executeFind(new HibernateCallback() {
            public Object doInHibernate(Session session)
                    throws HibernateException, SQLException {
                Criteria c = session.createCriteria(GroupMember.class);
                if (null != groupid)
                    c.add(Restrictions.eq("Groupid.id", groupid));

                if (pagerecord != -1)
                    c.setMaxResults(pagerecord);
                if (startIndex != -1)
                    c.setFirstResult(startIndex);
                return c.list();
            }
        });
    }

when call doInHibernate method ,spring will privode a session,and close it after calling.but you set laza-load is true,so in the doInHibernate method,the set collection don't init,when you out of session,call the getSet method ,so you get this error.
I have a litter knowleage in spring and hibernate,so it maybe not right,last,say sorry for my bad eglish.


Top
 Profile  
 
 Post subject: i make another changes
PostPosted: Sat Aug 12, 2006 1:01 pm 
Newbie

Joined: Fri Aug 11, 2006 2:30 pm
Posts: 3
Hi,thanks for response, I try different issues, but still doesn't work. Finally I changed two files, shown below, but I get another error message, it's look like one row from the database just simple disappear. I sent here this two files I change and also MemberDaoHibernateImpl
Address.hbm.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sf.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
   <class name="org.noip.jorg.pms.manager.AddressImpl" table="addresses" [b]lazy="false"[/b]>
      <id name="id" column="address_id" type="java.lang.Integer" unsaved-value="0">
         <generator class="native"></generator>
      </id>
      <property name="city" column="city" type="java.lang.String"></property>
      <property name="state" column="state" type="java.lang.String"></property>
      <property name="zip" column="zip" type="java.lang.String"></property>
      <property name="country" column="country" type="java.lang.String"></property>
      <property name="phone" column="phone" type="java.lang.String"></property>
      <property name="fax" column="fax" type="java.lang.String"></property>
      <one-to-one name="member" class="org.noip.jorg.pms.manager.MemberImpl" property-ref="address" [color=red]lazy="false"[/color]></one-to-one>
      <one-to-one name="customer" class="org.noip.jorg.pms.manager.CustomerImpl" property-ref="address" [color=red]lazy="false"[/color]></one-to-one>
   </class>
</hibernate-mapping>   



Member.hbm.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sf.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
   <class name="org.noip.jorg.pms.manager.MemberImpl" table="members">
      <id name="id" column="member_id" type="java.lang.Integer" unsaved-value="0">
         <generator class="native"></generator>
      </id>
      <set name="groups" table="members_groups">
         <key column="member_id"></key>
         <many-to-many column="group_id" class="org.noip.jorg.pms.manager.GroupImpl"></many-to-many>
      </set>
      <many-to-one name="address" class="org.noip.jorg.pms.manager.AddressImpl" column="address_id" [color=red]unique="true" cascade="save-update" lazy="false"[/color]></many-to-one>
      <many-to-one name="contact" class="org.noip.jorg.pms.manager.ContactImpl" column="contact_id" unique="true" [color=red]cascade="save-update" lazy="false"[/color]></many-to-one>
      <set name="tasks" table="members_tasks">
         <key column="member_id"></key>
         <many-to-many column="task_id" class="org.noip.jorg.pms.project.Task"></many-to-many>
      </set>
      
   
   </class>
</hibernate-mapping>



MemberDaoHibernateImpl [\b]
Code:
/**
*
*/
package org.noip.jorg.pms.manager.dao;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.noip.jorg.pms.manager.Member;
import org.noip.jorg.pms.manager.MemberImpl;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
* Implements data access methods for Member dao.
*
* @author lipa
* @see MemberDao
*/
public class MemberDaoHibernateImpl extends HibernateDaoSupport implements MemberDao {

    /* (non-Javadoc)
     * @see org.noip.jorg.pms.manager.dao.MemberDao#deleteAll()
     */
    public void deleteAll() throws DataAccessException{
        List members = getHibernateTemplate().find("FROM MemberImpl m");
        getHibernateTemplate().deleteAll(members);
    }

    /* (non-Javadoc)
     * @see org.noip.jorg.pms.manager.dao.MemberDao#find(java.lang.Integer)
     */
    public Member find(Integer id) {
        Member memeber = null;
        String query = "FROM MemberImpl m WHERE m.id = " + id;
        List result = getHibernateTemplate().find(query);
        if(result.size() > 0)
            memeber = (MemberImpl) (result.get(0));
        return memeber;
    }

    /* (non-Javadoc)
     * @see org.noip.jorg.pms.manager.dao.MemberDao#findAll()
     */
    @SuppressWarnings("unchecked")
    public Set<Member> findAll() {
        String query = "FROM MemberImpl m";
        List<Member> list = getHibernateTemplate().find(query);
        Set<Member> tree = new HashSet<Member>();
       
        for(Member m:list){
           tree.add((Member)m);
        }
        return (Set<Member>) tree;
    }

    /* (non-Javadoc)
     * @see org.noip.jorg.pms.manager.dao.MemberDao#countAll()
     */
    public int countAll() {
        return ((Integer) getHibernateTemplate().find(
        "SELECT count(*) FROM MemberImpl m").get(0)).intValue();
    }

    /* (non-Javadoc)
     * @see org.noip.jorg.pms.manager.dao.MemberDao#save(org.noip.jorg.pms.manager.Member)
     */
    public void save(Member member) {
        getHibernateTemplate().saveOrUpdate(member);
    }

    /* (non-Javadoc)
     * @see org.noip.jorg.pms.manager.dao.MemberDao#delete(org.noip.jorg.pms.manager.Member)
     */
    public void delete(Member member) {
        getHibernateTemplate().delete(member);
    }

   
}

I can't figure out why one row disappear in database :/, i think this is the problem but i don't know where can be a mistake.
[b]My error message:

Code:
Hibernate: select memberimpl0_.member_id as member1_, memberimpl0_.address_id as address2_10_, memberimpl0_.contact_id as contact3_10_ from members memberimpl0_
Hibernate: select addressimp0_.address_id as address1_2_, addressimp0_.city as city13_2_, addressimp0_.state as state13_2_, addressimp0_.zip as zip13_2_, addressimp0_.country as country13_2_, addressimp0_.phone as phone13_2_, addressimp0_.fax as fax13_2_, memberimpl1_.member_id as member1_0_, memberimpl1_.address_id as address2_10_0_, memberimpl1_.contact_id as contact3_10_0_, customerim2_.customer_id as customer1_1_, customerim2_.firm_name as firm2_15_1_, customerim2_.description as descript3_15_1_, customerim2_.address_id as address4_15_1_ from addresses addressimp0_ left outer join members memberimpl1_ on addressimp0_.address_id=memberimpl1_.address_id left outer join customers customerim2_ on addressimp0_.address_id=customerim2_.address_id where addressimp0_.address_id=?
2006-08-12 18:36:21 org.hibernate.event.def.DefaultLoadEventListener onLoad
INFO: Error performing load command
org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [org.noip.jorg.pms.manager.AddressImpl#8892]
   at org.hibernate.ObjectNotFoundException.throwIfNull(ObjectNotFoundException.java:27)
   at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:118)
   at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:151)
   at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:79)
   at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:655)
   at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:261)
   at org.hibernate.type.EntityType.resolve(EntityType.java:286)
   at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:105)
   at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:530)
   at org.hibernate.loader.Loader.doQuery(Loader.java:436)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
   at org.hibernate.loader.Loader.doList(Loader.java:1593)
   at org.hibernate.loader.Loader.list(Loader.java:1577)
   at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
   at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
   at org.springframework.orm.hibernate3.HibernateTemplate$29.doInHibernate(HibernateTemplate.java:837)
   at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366)
   at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:828)
   at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:820)
   at org.noip.jorg.pms.manager.dao.MemberDaoHibernateImpl.deleteAll(MemberDaoHibernateImpl.java:28)
   at org.noip.jorg.pms.manager.MembersImpl.deleteAll(MembersImpl.java:32)
   at org.noip.jorg.pms.manager.AddressImplTest.setUp(AddressImplTest.java:19)
   at junit.framework.TestCase.runBare(TestCase.java:125)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)



Top
 Profile  
 
 Post subject: one-to-one and one-to-many
PostPosted: Mon Aug 14, 2006 9:53 pm 
Newbie

Joined: Thu May 05, 2005 6:44 am
Posts: 2
in your test,when you perform a deleteAll() method,first you find member, like 'select * from members',then call this line "getHibernateTemplate().deleteAll(members); ",I find this sql which was printed is "select * from addresses addressimp0_ left outer join members memberimpl1_ on addressimp0_.address_id=memberimpl1_.address_id left outer join customers",there has two left join,maybe two else table has no data ,so it just like a row disappear.


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

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.