hello good people i'm developping an application where all the pojos are exposed as interface but we map the real implementation class.we are using spring and JPA annotation.i'm about to test the one-to-one relationship and i'm having a light problem with the interface.
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionContainer' defined in class path resource [META-INF/model-config.xml]:
Cannot resolve reference to bean 'sessionFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sessionFactory' defined in class path resource [META-INF/model-config.xml]:
Invocation of init method failed; nested exception is org.hibernate.AnnotationException:
@OneToOne or @ManyToOne on com.mycompany.project.subproject.model.UserAccountImpl.profile references an unknown entity: com.mycompany.project.
so before this class all the other mapped class are working as expected so i'll only post part of the applicationContext
file that i named model-config.xml
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
...
<value>com.mycompany.project.subproject.model.UserProfileImpl</value>
<value>com.mycompany.project.subproject.model.UserAccountImpl</value>
...
</list>
</property>
here are the two involved class UserProfileImpl.java
and UserAccountImpl.java
//UserAccountImpl Class
@Entity
@Table(name ="USER_ACCOUNT")
public class UserAccountImpl implements UserAccount {
@Id @GeneratedValue
@Column(name="USER_ACCOUNT_ID")
private Long ID;
...
@OneToOne
@JoinColumn(name="USER_PROFILE_ID")
private UserProfile profile;
...
}
//UserProfileImpl class
@Entity
@Table(name="USER_PROFILE")
public class UserProfileImpl implements UserProfile {
@Id @GeneratedValue
@Column(name="USER_PROFILE_ID")
private Long ID;
....
@OneToOne(mappedBy="profile")
private UserAccount userAccount;
....
}
i'm still not very confortable with hibernate yet so i'm wondering if i should Change the UserProfile
reference in UserAccountImpl
to UserProfileImpl
.Then again the same can happen in the UserProfileImpl
for userAccount
reference since it's a bidirectional navigation stuff.
What's the best option that will no break the consistency of the structure?
Thanks for reading this