Micronaut Data - No bean of type [org.hibernate.SessionFactory]

Viewed 1782

First to mention - I had everything up and running. The only change I made was adding some more repositories to the code.

Then I got:

15:47:58.126 [pool-2-thread-4] ERROR i.m.h.s.netty.RoutingInBoundHandler - Unexpected error occurred: Failed to inject value for parameter [sessionFactory] of class: io.micronaut.transaction.hibernate5.HibernateTransactionManager

Message: No bean of type [org.hibernate.SessionFactory] exists for the given qualifier: @Named('default'). Make sure the bean is not disabled by bean requirements (enable trace logging for 'io.micronaut.context.condition' to check) and if the bean is enabled then ensure the class is declared a bean and annotation processing is enabled (for Java and Kotlin the 'micronaut-inject-java' dependency should be configured as an annotation processor). Path Taken: new HibernateTransactionManager([SessionFactory sessionFactory],DataSource dataSource,Interceptor entityInterceptor) io.micronaut.context.exceptions.DependencyInjectionException: Failed to inject value for parameter [sessionFactory] of class: io.micronaut.transaction.hibernate5.HibernateTransactionManager

I checked a lot of articles about that, but they all mention dependenices. But i havn't change my dependenices. So i started to investigate. But up to now without success.

I double checked my gradle.build

kapt 'io.micronaut.data:micronaut-data-processor:1.0.2'
implementation 'io.micronaut.data:micronaut-data-hibernate-jpa:1.0.2'
implementation 'io.micronaut.configuration:micronaut-jdbc-hikari'
runtime 'org.postgresql:postgresql:42.2.12'
testImplementation 'com.h2database:h2:1.4.200'

I also make sure I use the correct versions, but the unit test won't run.

Using Gradle 6.4.1 with micronaut 1.3.5 and obviously data 1.0.2 with jpa. Any ideas?

Also activated the condition trace, but nothing about the sessionfactory. Just some spring stuff, but i do not use spring, so therefore i think its okay.

15:47:39.037 [Test worker] DEBUG i.m.context.condition.Condition - Bean [io.micronaut.jdbc.spring.$DataSourceTransactionManagerFactory$TransactionAwareDataSourceListener1Definition] will not be loaded due to failing conditions:
15:47:39.038 [Test worker] DEBUG i.m.context.condition.Condition - * Class [org.springframework.jdbc.datasource.DataSourceTransactionManager] is not present

Any ideas .. cause that drives me a little crazy :D

Oliver

2 Answers

finally i found the mistake :-)

data class DataX(
        @Id
        val id: String
) {

val yrefs
    get() = _yrefs.toList()

@OneToMany(cascade = [CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH], orphanRemoval = true, fetch = FetchType.EAGER,
           mappedBy = "yref") // < this was wrong must be xref
private val _yrefs= mutableListOf<DataY>()
}


data class DataY(
        @Id
        val id: String
) {
val zrefs
    get() = _zrefs.toList()

@OneToMany(cascade = [CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH], orphanRemoval = true, fetch = FetchType.EAGER,
           mappedBy = "zref")
private val _zrefs = mutableListOf<DataZ>()

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "x_ref_id")
var xref: DataX? = null
}

I'm newbie with Kotlin and Micronaut, so I'm not sure about it. but Your data class started with lower letter?

For example:

@Entity
data class dataBook (
        @Id
        @GeneratedValue
        val id: Long
)
Related