-->
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.  [ 3 posts ] 
Author Message
 Post subject: Beginner questions...
PostPosted: Thu Jul 10, 2008 2:29 pm 
Beginner
Beginner

Joined: Mon Jul 07, 2008 8:07 pm
Posts: 42
I have a few questions about Hibernate. I'm using it with Spring right now and to this point I've had no success in getting it up and running.

So a session factory (as defined in the Spring beans) is essentially a database connection pool? Is that accurate? If that is so, why do I need a data source? I have seen other tutorials covering the integration of Spring and Hibernate and not very many had a data source bean in their main Spring file. I had noticed that some tutorials integrate the database connection right in the session factory.
As far as mapping classes to database tables, does Hibernate automatically create and format the tables if they are not already present in the database, or do I need to build the tables myself? (I've kind of used the Hibernate tools in ant, can this be done in Java?) I kind of understand the logic behind schemas: they're like a Java to SQL map that tells the database how to format the tables, right? Also, do I need to include a hibernate.cfg.xml file in my classpath if I'm using the Spring beans? Why/why not?
I have also noticed that if I include the entire spring framework (spring-2.5.jar) in my library path, all of my applications will go down. Why is this?

I know it's a lot to ask, but I really need to get this application up and running :)

- TK


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 11, 2008 10:45 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
As far as Hibernate creating tables, well, you have to tell Hibernate to do it. If you ask Hibernate to, either in the xml, or programatically through the SchemaExport class, it will drop any existing tables and recreate the new ones.

To get things working, start small, achieve small victories, and move from there. Just get Hibernate working with Hibernate, maybe just creating tables for you. Make sure you can add and update, and go on.

Here are some free tutorials on getting up and running with Hibernate that you might find interesting. There's some discussion of the SchemaExport class as well for creating database tables.



http://jpa.ezhibernate.com/Javacode/learn.jsp?tutorial=02validatingthehibernateenvironment

Good luck!

-Cameron McKenzie

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 11, 2008 9:08 pm 
Regular
Regular

Joined: Mon Aug 22, 2005 1:11 pm
Posts: 50
Location: Pasadena, CA
If you are using annotation with spring you dont have to have hibernate.cfg.xml spring will manage that for you. You just need to list your class in the sessionFactory bean.

If you want Hibernate to generate your tables for you (again using Spring) you just to set generateDdl to true in your adapter bean which part of your entity bean.

Like so.

Code:
  <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="jpaVendorAdapter">
      <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
        <property name="databasePlatform" value="org.hibernate.dialect.DerbyDialect" />
        <property name="showSql" value="true" />
         <property name="generateDdl" value="true" />
      </bean>
    </property>
  </bean>


-Mike[/code]


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