typesafehub / play-spring-data-jpa

Other
43 stars 26 forks source link

play 2.4 #16

Open heftyy opened 9 years ago

heftyy commented 9 years ago

I have been trying to use this example with play 2.4 but i am getting this error: No implementation for models.PersonRepository was bound. It works fine until play 2.3.9

Clandestino commented 9 years ago

I have the same problem. Any issue?

craicoverflow commented 9 years ago

Try updating your dependencies in your build.sbt from http://mvnrepository.com/

flyingzhang commented 9 years ago

Any idea? I have tried to update the hibernate em/spring framework/spring data jpa dependencies, but it still failed with the same problem.

nvelu-equinix commented 9 years ago

facing the same issue. an updates please?

flyingzhang commented 9 years ago

This is because of the new DI design in play 2.4, which use guice as the main DI implementation. Try using spring-guice module for integrate spring into the system. The first solution I have seen is play24-guice-spring.

eximius313 commented 8 years ago

I managed to get it working with spring-guice but it failed to get EntityManager throwing following exception:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: At least one JPA metamodel must be present!

so I gave up....

unterstein commented 8 years ago

Hi @eximius313,

I had the similar issues, maybe me pull request https://github.com/typesafehub/play-spring-data-jpa/pull/20 can help you.

Cheers Johannes

craicoverflow commented 8 years ago

Annotate your PersonRepository interface with @ImplementedBy..

@ImplementedBy(PersonRepositoryImpl.class)
public interface PersonRepository {
    //method declarations
}
craicoverflow commented 8 years ago

@eximius313 Did you try adding the JPA meta model generator ref?

https://docs.jboss.org/hibernate/orm/5.0/topical/html/metamodelgen/MetamodelGenerator.html

eximius313 commented 8 years ago

@unterstein I'm using PostgreSQL. Play requires me to use persistence.xml file. However, in your implementation you are using AnnotationConfiguration. Can these both solutions coexist?

Kind regards

unterstein commented 8 years ago

@eximius313,

sure. I just used programmatically configuration because i eliminated Ebean and it was far easier this way.

You could do something like this:

Configuration

    @Configuration
    @EnableJpaRepositories("models")
    public static class SpringDataJpaConfiguration {

        @Bean
        public EntityManagerFactory entityManagerFactory() {
            return Persistence.createEntityManagerFactory(DEFAULT_PERSISTENCE_UNIT);
        }

        @Bean
        public HibernateExceptionTranslator hibernateExceptionTranslator() {
            return new HibernateExceptionTranslator();
        }

        @Bean
        public JpaTransactionManager transactionManager() {
            return new JpaTransactionManager();
         }
     }

persistence.xml

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">

    <!-- postgres -->

    <persistence-unit name="default">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
            <property name="hibernate.archive.autodetection" value="class" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
            <property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
            <property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/querydsl" />
            <property name="hibernate.connection.username" value="querydsl" />
            <property name="hibernate.connection.password" value="querydsl" />
            <!-- <property name="hibernate.show_sql" value="true"/> -->
            <property name="hibernate.flushMode" value="FLUSH_AUTO" />
            <property name="hibernate.hbm2ddl.auto" value="update" />
        </properties>
    </persistence-unit>

</persistence>

I took the persistence.xml configuration from https://gist.github.com/mortezaadi/8619433. You should adapt this configuration according to your needs.

Kind regards Johannes

eximius313 commented 8 years ago

@unterstein is is necessary to remove javaJpa from libraryDependencies in build.sbt file?

unterstein commented 8 years ago

@eximius313 I think this dependency was not available anymore..

eximius313 commented 8 years ago

Well, I'm using it now and it allows for using JPA in my project. Why would it be not available?

unterstein commented 8 years ago

If it is available and you need classes from this dependency, just use it :-).

I don´t know why i removed this dependency to be honest...but in this case, spring data provides all relevant jpa dependencies :)