-->
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.  [ 11 posts ] 
Author Message
 Post subject: Hibernate Tools, Spring/Hibernate and Eclipse plugin
PostPosted: Mon Oct 29, 2007 12:25 am 
Newbie

Joined: Tue Sep 11, 2007 5:37 am
Posts: 1
Hi there,

I would like to use Hibernate Tools to automate some of my mapping / DAO code generation. When I installed and ran the hibernate tools eclipse plugin it seems to demand that I have a hibernate.cfg.xml file. As I am using Spring / Hibernate I dont have a hibernate.cfg.xml file - the equivalent configuration is in the application context /session factory configuration. It would seem that there is no option to point Hibernate Tools to my application context definition instead of hibernate.cfg.xml ?

Do I duplicate my configuration and create a hibernate.cfg.xml to keep Hibernate Tools happy ? Should I be able to supply the equivalent information in another form ? What do other people do ? I am surprised that I cant find other posts on the same topic.

Cheers,

Kieran


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 29, 2007 2:16 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
we dont require a cfg.xml, you can just use a persistence.xml ;)

Anyway, yes the "workaround" is to use a cfg.xml yes.

If someone where to implement this kinda support I would be more than happy to apply the patch - optimally it should work both from pure ant and eclipse and not be dependent on additional libraries.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 21, 2007 12:25 pm 
Newbie

Joined: Mon Apr 09, 2007 12:25 pm
Posts: 19
Location: Boston, MA
I'm also trying to integrate Eclipse, Spring, Hibernate and Hibernate Tools.

Max, I apologize, but I didn't quite follow your answer. To confirm: are you saying that yes, we must create a Hibernate configuration file in order to use the tools, even if this is a duplication of what is contained within our Spring context files?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 22, 2007 4:27 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes if you are not using cfg.xml or standard persistence.xml or add the hbm.xml files manually to the console configuraiton I don't have any way to "get" what mappings you have.

Of course if someone from the community would contribute a way (without a tons of extra dependencies) to read and understand other ways of configuring a Configuration then that would be very welcome.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 22, 2007 11:06 am 
Newbie

Joined: Mon Apr 09, 2007 12:25 pm
Posts: 19
Location: Boston, MA
Thanks for spelling it out, Max.


Top
 Profile  
 
 Post subject: cfg.xml when using spring
PostPosted: Fri Jan 09, 2009 12:54 pm 
Newbie

Joined: Fri Jan 09, 2009 12:52 pm
Posts: 6
Has a work around been put in place for this yet?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 09, 2009 3:44 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
no - if anyone want to attack it I would glad to help/point in the right direction...

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2009 2:58 pm 
Newbie

Joined: Mon Feb 02, 2009 2:49 pm
Posts: 15
While I haven't really solved this problem, I have gotten around it for myself. Maybe this will help someone else.

I am using ant, so what I did was get an XPath ant task and harvest the data I needed from my applicationContext.xml.

You need the Andariel library: http://andariel.uworks.net/

Code:
<taskdef resource="net/uworks/andariel/andariel.properties">
     <classpath>
       <pathelement location="andariel-1.2.3.jar" />
     </classpath>
</taskdef>


then I wrote a target that makes a propeties file. It creates a property called "temp.propfile" that you can then use in a Configuration section.

Code:
<target name="-make-propfile">
      <!-- extract properties from the applicationContext.xml file -->
         <xpath file="${src.dir}/applicationContext.xml" expression="/sb:beans/sb:bean[@id='SelboardDataSource']/sb:property[@name='driverClassName']/@value" outputproperty="hibernate.connection.driver_class">
          <namespace prefix="sb" uri="http://www.springframework.org/schema/beans"/>
       </xpath>
       <xpath file="${src.dir}/applicationContext.xml" expression="/sb:beans/sb:bean[@id='SelboardDataSource']/sb:property[@name='url']/@value" outputproperty="hibernate.connection.url">
          <namespace prefix="sb" uri="http://www.springframework.org/schema/beans"/>
       </xpath>
       <xpath file="${src.dir}/applicationContext.xml" expression="/sb:beans/sb:bean[@id='SelboardDataSource']/sb:property[@name='username']/@value" outputproperty="hibernate.connection.username">
          <namespace prefix="sb" uri="http://www.springframework.org/schema/beans"/>
       </xpath>
       <xpath file="${src.dir}/applicationContext.xml" expression="/sb:beans/sb:bean[@id='SelboardDataSource']/sb:property[@name='password']/@value" outputproperty="hibernate.connection.password">
          <namespace prefix="sb" uri="http://www.springframework.org/schema/beans"/>
       </xpath>
       <xpath backwardscompatible="true" file="${src.dir}/applicationContext.xml" expression="//sb:prop[@key='hibernate.dialect']/text()" outputproperty="hibernate.dialect">
          <namespace prefix="f" uri="http://www.w3.org/2005/02/xpath-functions"/>
          <namespace prefix="sb" uri="http://www.springframework.org/schema/beans"/>
       </xpath>
       <trim name="hibernate.dialect"/>
       
       <property name="tmpdir" location="${rev-eng.dir}/${temporary.properties.dir}"/>
       <mkdir dir="${tmpdir}" />
      <tempfile property="temp.propfile" prefix="jdbc-reverse-eng-" suffix=".properties" destdir="${tmpdir}"/>
       <echo>writing out stuff to file '${temp.propfile}'</echo>
      <echo file="${temp.propfile}">
         hibernate.connection.driver_class=${hibernate.connection.driver_class}
         hibernate.connection.url=${hibernate.connection.url}
         hibernate.connection.username=${hibernate.connection.username}
         hibernate.connection.password=${hibernate.connection.password}
         hibernate.dialect=${hibernate.dialect}
         
         hibernate.connection.aggressive_release=false
         hibernate.connection.release_mode=after_transaction
         hibernate.connection.autocommit=true
         hibernate.connection.pool_size=0
         hibernate.current_session_context_class=thread
         hibernate.cache.use_query_cache=false
         hibernate.cache.use_second_level_cache=false
       </echo>
    </target>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2009 4:23 pm 
Newbie

Joined: Mon Feb 02, 2009 4:21 pm
Posts: 1
jeffwalker, thank you for code.
and my site: [link]http://www.google.com[/link]


Last edited by MrAntonio on Thu Nov 12, 2015 9:39 am, edited 3 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2009 6:35 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hmm...if someone created the corresponding java code for doing that extraction I would easily be able to enable that kind of support...

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re: Hibernate Tools, Spring/Hibernate and Eclipse plugin
PostPosted: Tue Jul 13, 2010 12:20 pm 
Newbie

Joined: Tue Jul 13, 2010 12:11 pm
Posts: 1
This is an old post but in case someone else finds this and needs an answer I got Hibernate annotations to work with hibernate tools and spring. I created the hibernate.cfg.xml and it only contains a list of classes I want mapped. I created hibernate.properties to have the database dependent properties and then in spring I have my session factory like this.

Spring configuration:
<bean id="hibernateSessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<!-- list of classes for annotations mapping -->
<property name="configLocation" value="classpath:hibernate.cfg.xml"/>

<!-- database dependent configuration: change these two for oracle/hslq -->
<property name="dataSource" ref="hsqlDataSource" />
<property name="hibernateProperties" ref="hsqlHibernateProperties"/>
</bean>

Hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="hibernateSessionFactory">
<mapping class="com.Class1"/>
<mapping class="com.Class2"/>
<mapping class="com.Class3"/>
</session-factory>
</hibernate-configuration>

I can create the hibernate console using the hibernate.cfg.xml and properties file. I just create a datasource in the console rather than reading from my spring config. Not perfect but it works fine. The only duplication is that I configure the datasource both in spring and hibernate console.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 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.