With the Spring Boot JPA, how can I tell Spring to...
# spring
b
With the Spring Boot JPA, how can I tell Spring to use a .hbm.xml to declare a managed type and not use annotations? I have tried `spring.jpa.properties.hibernate.mappingLocations = classpath:/hibernate/.hbm.xml` but I still receive a
Caused by: java.lang.IllegalArgumentException: Not a managed type: class com.github.bkenn.jpafx.model.Vendor
exception.
stackoverflow 1
n
stupid question and please don’t be offended why are you still using hbm files in 2018?
b
I understand. I don't like it. But I am messing around with Spring Boot and TornadoFX. I tried the annotation approach but it is not working. Here is an example with annotations:
Copy code
val idProperty = SimpleIntegerProperty()
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
var id by idProperty
TornadoFX provides a delegated property for JavaFX Properties. So when you set the
id
value it is delegated to the
idProperty
value. However, Hibernate is still interpreting the id as IntegerProperty and not Int. Thus, me trying to work around the annotation approach.
n
i understand (well, i understand this is a technical requirement) however, i wonder if your problem is kotlin related did you manage to get that working in plain java? i’m afraid the issue comes from the jpa mapping...
b
true, I move elsewhere for an answer then.
t
There is often a reason to have to do something the old way in a project, even in our days 🙂 . We had to use hbm files in a project very recently because it was a migration to Spring Boot from an old non-spring project. We were trying to perform the minimum amount of work possible in the first phase of the migration. So, first make it work with the existing hbm files, and then re-write it with annotations. I think the mappings are declared under:
spring.jpa.mapping-resources
and not under hibernate that you mention in your first message. Maybe it is worth trying it? Let me know if it helped.
Here is an example from an application.yml: spring: jpa: mapping-resources: - hibernate_mappings/CustomTypes.hbm.xml - hibernate_mappings/access/Groups.hbm.xml
b
Unfortunately, receiving the same exception being thrown when adding the
spring.jpa-mapping-resources
. Here is a bare example https://github.com/bkenn/JpaBootFX. I just tried with the annotation approach in plain java and it does run and save entities. So this may be a Kotlin-Hibernate related issue.
t
Not sure what the problem is then 🤔, sorry that didn’t help. The project I mentioned was in Java (unfortunately 😛).
b
No problems, I will eventually discover the issues. Thanks for the help though!
I was using 1.5.10.RELEASE. I bumped to 2.0.0.RC1 and now works.
spring.jpa-mapping-resources
doesn't exist in 1.5.*. 🎉🎉
🎉 1
t
I should have mentioned I was working with SB2. Well done! 👍
172 Views