Hibernate and JPA - Error mapping. Built-in class, open via interface

We have a set of interfaces used as APIs and links from other modules. A set of specific implementations of these interfaces, private to the "main" application module. These classes contain a number of annotations (JPA, as well as XStream for XML serialization).

I have a problem. We have a user class that has several fields related to location in it. We would like to flip them into the Address class. We want the data (at the moment) to remain in the same table. An approach is an embedded class.

The problem is that type signatures should only refer to other interfaces in order to satisfy the interfaces that they implement.

When I try to save UserImpl, I get an exception:

org.hibernate.MappingException: it is possible not to determine the type for: com.example.Address, at the table: User, for columns: [Org.hibernate.mapping.Column (address)]

Code example:

interface User { int getId(); String getName(); Address getAddress(); } @Entity class UserImpl implements User { int id; String name; Address address; int getId() { return id; } void setId(int id) { this.id = id; } String getName() { return name; } String setName(String name) { this.name = name; } @Embedded Address getAddress() { return address; } void setAddress(Address address) { this.address = address; } } interface Address { String getStreet(); String getCity(); String getState(); String getZip(); String getCountry(); } @Embeddable class AddressImpl implements Address { String street; String city; String state; String zip; String country; public String getStreet() { return street; } public String getCity() { return city; } public String getState() { return state; } //... etc } 
+7
hibernate jpa persistence
source share
1 answer

You can use @Target Hibernate Annotation (which is a Hibernate extension for JPA annotations)

 @Embedded @Target(AddressImpl.class) Address getAddress() { return address; } 
+13
source share

All Articles