Results 1 to 8 of 8

Thread: Spring/Hibernate/JBoss SessionFactory config problem

  1. #1
    Join Date
    Sep 2004
    Location
    London
    Posts
    311

    Default Spring/Hibernate/JBoss SessionFactory config problem

    hi all,
    i have developed a webapplication that consists of two modules, a backend.jar module that contains backend code (uses hib & spring) and a WebApp (webwork based) that uses the backend.jar for interacting with the database.
    I wanted to configure my SessionFactory dynamically, without hardcoding the mapping files that i was going to use in appconfig.xml, so i wrote this in the appContext.xml

    Code:
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    	    <property name="dataSource">
    			<ref bean="dataSource"/>
    	    </property>
    	    	      
    	    <property name="mappingLocations">
    			<value>classpath*:**/*.hbm.xml</value>
    	    </property> 
    .....
    Now, when i run my jUnit tests for backend.jar module, everything is fine, i can insert/delete etc..
    However when i run my app in JBoss/Tomcat, when the web module is trying to insert something in the database i got a big exception stating that it cannot find Entity <myobjectconfiguredinhbm.xmlfile>, so it's like it is not able to see the hbm.xml files
    now, i am pretty sure the web module is configured properly regarding spring xml files...... i am going to do some integration tests between web and backend modules, but i was wondering if anyone has encountered this problem before..

    When i replaced the above configuratin with this one
    Code:
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    	    <property name="dataSource">
    			<ref bean="dataSource"/>
    	    </property>
    	    
    	    <property name="mappingResources">
    			<list>
    				<value>bus/dto/AgencyImpl.hbm.xml</value>
    				<value>bus/dto/JobApplicationImpl.hbm.xml</value>
    			</list>
    		</property>
    everything works like a charm
    i am including spring.jar version 2.0, i was wondering if anyone has encountered this problem before......
    Since everything works in the lattter configuration, my guess is that the problem is in the former configuration...

    any help?

    thanks in advance and regards
    marco

  2. #2
    Join Date
    Sep 2004
    Location
    London
    Posts
    311

    Default

    Hello,
    as i was supposing, my integration tests failed with following exception :
    Code:
    Caused by: org.hibernate.MappingException: Unknown entity: bus.dto.AgencyImpl
            at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:610)
            at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1246)
            at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:180)
            at org.hibernate.event.def.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:459)
            at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:84)
            at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
            at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:501)        at org.hibernate.i
    if i dont use mappingLocations but declare the hbm files used, everything works fine..
    i take it as that this is happening because my hibernate classes are in a separate jars from the web classes......

    anyone had succeeded with same settings?
    thanks and regars
    marco

  3. #3
    Join Date
    Mar 2007
    Posts
    515

    Default

    Try using mappingJarLocations property of session factory bean.

  4. #4
    Join Date
    Sep 2004
    Location
    London
    Posts
    311

    Default

    Hello Andrei,
    that would work but it will fail my tests...
    i have followign situation

    - backend.jar (containing hibernate xml files)
    - webapp.jar that has backend.jar as dependency

    if i use mappingJarLocation, i suspect my backend tests will fail because i run my tests before building jar (i m using maven2), and so at the moment of running junit spring won't be able to find the jar file
    unless i use a separate sessionFactory for deployment and for testing, then for deployment i could use mappingJarLocation and for tests i can use mappingLocations.
    i was wondering if there is a setting that accomodates both......

    any ideas?

    thanks and regards
    marco

  5. #5
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Can't you just use two different configurations for the sessionFactory; one for each environment?
    Last edited by karldmoore; Aug 29th, 2007 at 11:56 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  6. #6
    Join Date
    Sep 2004
    Location
    London
    Posts
    311

    Default

    hello again karldmoore,
    yes i can... i was trying to explore the possibility of having just one session that will accomodate both cases...
    looks it's impossible unless i:
    - mock dao tests
    - do integration tests separately (once i got jars from web and backend)

    however, having 2 different session factory does not harm, so i'll go that way

    thanx again and regards
    marco

  7. #7
    Join Date
    Jun 2007
    Posts
    12

    Default

    Your problem might be a different symptom of the same one I was encountering here: hibernate expects to load its configuration from the same classloader as it was loaded, so if you've put it in a shared location, it can only load configuration files from shared locations.

  8. #8
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Quote Originally Posted by MmarcoM View Post
    yes i can... i was trying to explore the possibility of having just one session that will accomodate both cases
    I know what you mean, it's nice to just have the one configuration. If everythings the same in both places, then there are no worries. If not.........
    Last edited by karldmoore; Aug 29th, 2007 at 11:56 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •