-->
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: New user, problem mapping...
PostPosted: Sun Dec 02, 2007 10:14 am 
Beginner
Beginner

Joined: Sat Dec 01, 2007 4:34 pm
Posts: 20
I'm trying to translate a java ee project into a project using spring and hibernate. I'm using a mysql database.

I've read some of the tutorials, but I think it's a bit hard to figure all the things out by myself. I would be very happy if someone could help me on the right track... I'm trying to map the project to a table, User in mysql. Can someone please help me?


applicationContext.xml


Code:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="${jdbc.driverClassName}"/>
    <property name="url" value="${jdbc.url}"/>
    <property name="username" value="${jdbc.username}"/>
    <property name="password" value="${jdbc.password}"/>
  </bean>
 
  <!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->
   
  <hibernate-mapping>
       
    <class name="User" table="User">
        <id name="id">
            <generator class="sequence">
                <param name="sequence">Username</param>
            </generator>
        </id>
        <property name="Password" column="Password"/>
        <property name="Firstname" column="Firstname"/>
        <property name="Lastname" column="Lastname"/>
        <property name="Usertype" column="Usertype"/>
    </class>

  </hibernate-mapping>
</beans>



Usertable in mysql


Code:
CREATE TABLE IF NOT EXISTS User (
   Username  varchar(15)   NOT NULL default '',
   Password  varchar(15)   NOT NULL default '',
   Firstname varchar(25)   NOT NULL default '',
   Lastname  varchar(30)   NOT NULL default '',
   Usertype  varchar(30)   NOT NULL default '',
   PRIMARY KEY (Username)
) ENGINE=INNODB;



jdbc.properties

Code:
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/myApp?autoReconnect=true
jdbc.username=root
jdbc.password=admin
hibernate.dialect=org.hibernate.dialect.HSQLDialect


I also want to make a UserDAO where I could write methods with SQL-statements. How do I access the database in the UserDAO. In ejb you would use an entitymanager. How do you do it in Hibernate/Spring?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 03, 2007 3:32 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi vator,

You are using Spring...So use the hibernateTemplate Object to do your CRUD opertions in your Database.If you have more queries on how to use the hibernateTemplate, do google or check the spring forum.

If you want to use Hibernate yourself without the support of spring then kinldy read the "Getting Started" in the below link
http://www.hibernate.org/152.html

This will tell how to access your DB with SessionFactory and Session/Transaction.

Hope this helps!!!!

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 14, 2007 9:55 am 
Beginner
Beginner

Joined: Sat Dec 01, 2007 4:34 pm
Posts: 20
Thank you very much for your reply ramnath!

Which method would you recommend?

What is the better?


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.