-
Jul 12th, 2012, 08:18 AM
#1
Spring Data REST - Connecting for example to a mssql db config.
I am trying to alter the Spring Data REST demo project to point to an actual database, but it is not working.
So far I have tried the following changes, but I think I am lacking something.
Shared.Xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...ring-beans.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd">
<jdbc:embedded-database id="dataSource" type="HSQL"/>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.Hibernat eJpaVendorAdapter">
<property name="generateDdl" value="true"/>
<property name="database" value="SQL_SERVER"/>
</bean>
</property>
<property name="persistenceUnitName" value="jpa.mssql"/>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionM anager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
</beans>
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="jpa.sample">
<class>org.springframework.data.rest.example.Perso n</class>
<class>org.springframework.data.rest.example.Profi le</class>
<class>org.springframework.data.rest.example.Addre ss</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.connection.url" value="jdbc:hsqldb:mem:spring"/>
<property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/>
<property name="hibernate.connection.username" value="sa"/>
<property name="hibernate.connection.password" value=""/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
</properties>
</persistence-unit>
<persistence-unit name="jpa.mssql">
<class>org.springframework.data.rest.example.Perso n</class>
<class>org.springframework.data.rest.example.Profi le</class>
<class>org.springframework.data.rest.example.Addre ss</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServer2008Dialect"/>
<property name="hibernate.connection.url" value="jdbc:sqlserver://localhost:1433"/>
<property name="hibernate.connection.driver_class" value="com.microsoft.sqlserver.jdbc.SQLServerDrive r"/>
<property name="hibernate.connection.username" value="sa"/>
<property name="hibernate.connection.password" value="asdasd123"/>
<!-- property name="hibernate.hbm2ddl.auto" value="create-drop"/ -->
</properties>
</persistence-unit>
</persistence>
I cannot seem to understand why the entityManagerFactory specifies a dataSource if that information is also inside the persistence file. I don't know how to change that part.
This config wont start up and the logs don't really say what the problem is. It just says fail fail fail on everything it tries but does not give any reasons why its fails.
Please help.
-
Jul 12th, 2012, 08:48 AM
#2
Aah, never mind.
I just had to remove the dataSource setting in the entityManagerFactory and include the sqljdbc file in the INF/Lib folder.
Everything works, this stuff is amazing. So much functionality for almost no effort.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules