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 mysqlCode:
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.propertiesCode:
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?