Spring Data persistence

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Spring Data persistence

paddy
Hi

I've been learning JavaFX recently and putting together a small demo application.
I started with a JavaFx application + Spring boot using the following.
https://github.com/roskenet/springboot-javafx-support

I added Spring security and even BootstrapFX. In a few days I had something basic developed.
I was looking at some of the griffon examples and figured I'd try the replicate the application in Griffon.

There is alot to learn but I'm really stuggling to get over a hurdle with spring-data, I just can't seem to switch from the embedded driver H2 to SQL Server. My example was following the https://github.com/aalmiray/griffon-examples/tree/master/persistence/addressbook

I was able to get the Spring "addressbook-spring" to read data from SQL server database but the addressbook-spring-data just wont work. I was under the impression that if I just add the following to application.properties

{code}
spring.datasource.url=jdbc:sqlserver://localhost;databaseName=mydb
spring.datasource.username=sa
spring.datasource.password=xxxxxx
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.show-sql=true
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
spring.jpa.hibernate.ddl-auto = none
{code}

So I just tried updating the addressbook-spring-data example but it still attempts to use the H2 driver.
Any hints please?

Reply | Threaded
Open this post in threaded view
|

Re: Spring Data persistence

paddy
Ok, as luck would have it, I've made some progress.

I modified ContactConfiguration to the following

@Configuration
@EnableJpaRepositories
@EnableAutoConfiguration
@ComponentScan("org.kordamp.griffon.addressbook.springdata.beans")
@PropertySources({
        @PropertySource("application.properties")
                })

public class ContactConfiguration {
}

then application.properties to

{code}
spring.datasource.url=jdbc:sqlserver://localhost;databaseName=mydb
spring.datasource.username=sa
spring.datasource.password=xxxxxx
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.show-sql=true
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2014Dialect
spring.jpa.hibernate.ddl-auto=create-drop

{code}

Got a few errors regarding SQL server StandardDialectResolver.
See here https://hibernate.atlassian.net/browse/HHH-11604

so added the following

compile "org.hibernate:hibernate-core:$hibernate5Version"
compile "org.hibernate:hibernate-entitymanager:$hibernate5Version"

and upgraded some versions
springBootVersion       = 1.5.8.RELEASE
springVersion           =  5.0.1.RELEASE

I also had to change the following in ContactEntity

@Id
@GenericGenerator(
        name = "mySequenceGenerator",
        strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator",
        parameters = {
                @org.hibernate.annotations.Parameter(name = "sequence_name", value = "MY_SEQUENCE"),
                @org.hibernate.annotations.Parameter(name = "initial_value", value = "1000"),
               @org.hibernate.annotations.Parameter(name = "increment_size", value = "1")
        }
)
@GeneratedValue(generator = "mySequenceGenerator")


I'll try repeating the steps again just to be sure.