Hi - I am currently working on a project where i have used hibernate annotations, when i deploy it tomcat and run I am getting below error:
Exception Description: predeploy for PersistenceUnit [sampleapp] failed.
Internal Exception: Exception [TOPLINK-7161] (Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))): oracle.toplink.esse
ntials.exceptions.ValidationException
Exception Description: Entity class [class sample.hibernate.AccountRole] has no primary key specified. It should defi
ne either an @Id, @EmbeddedId or an @IdClass.
at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:615)
at oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider.createContainerEntityManagerFactory(EntityManagerFactor
yProvider.java:178)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntit
yManagerFactoryBean.java:214)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:2
51)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableB
eanFactory.java:1143)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBean
Factory.java:1110)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFact
ory.java:431)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:254)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:1
44)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:251)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:163)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactor
y.java:281)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:241)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3827)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4336)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:451)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: Exception [TOPLINK-28018] (Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))): oracle.toplink.essentials.e
xceptions.EntityManagerSetupException
I am not sure what configuration/metadata I am missing, below is my code and datamodel.SchemaCode:
create table Account
( AccountID NUMBER(10) not null,
Username VARCHAR2(255) not null,
Password VARCHAR2(64) null ,
FullName VARCHAR2(255) not null,
EmailAddress VARCHAR2(255) null ,
constraint PK_ACCOUNT primary key (AccountID) )
create table Role
( RoleID NUMBER(10) not null,
NameKey VARCHAR2(64) not null,
Description VARCHAR2(1024) null ,
constraint PK_ROLE primary key (RoleID) )
create table AccountRole
(
RoleID NUMBER(10) not null,
AccountID NUMBER(10) not null,
constraint PK_ACCOUNTROLE primary key (RoleID, AccountID)
)
Below are the hibernate classes for the above entities:Code:
Account.java
package sample.hibernate;
....
....
@Entity
@Table (name="Account")
public class Account
{
@Id
@Column(name = "AccountID")
private int accountID;
@Column(name = "Username")
private String username;
@Column(name="Password")
private String password;
@Column(name="AccountStatusTypeId")
private boolean isActive;
@Column(name="FullName")
private String fullName;
@Column(name="EmailAddress")
private String emailAddress;
private List<AccountRole> accountRoles = new LinkedList<AccountRole>();
.....
// Other Setter & getter API's
.....
.....
@OneToMany(fetch = FetchType.LAZY, mappedBy = "pk.account")
public List<AccountRole> getAccountRoles() {
return this.accountRoles;
}
public void setAccountRoles(List<AccountRole> accountRoles) {
this.accountRoles = accountRoles;
}
}
[u]AccountRole.java[/u]
package sample.hibernate;
@Entity
@Table(name = "ACCOUNTROLE")
@AssociationOverrides( { @AssociationOverride(name = "pk.account", joinColumns = @JoinColumn(name = "ACCOUNTID")),
@AssociationOverride(name = "pk.role", joinColumns = @JoinColumn(name = "ROLEID")) })
public class AccountRole
{
@Id
private AccountRolePk pk = new AccountRolePk();
@Column(name = "ACCOUNTID")
private int accountId;
@Column(name = "ROLEID")
private int roleId;
private AccountRolePk getPk()
{
return pk;
}
private void setPk(AccountRolePk pk)
{
this.pk = pk;
}
@Transient
public Account getAccount()
{
return getPk().getAccount();
}
public void setAccount(Account item)
{
getPk().setAccount(item);
}
@Transient
public Role getRole()
{
return getPk().getRole();
}
public void setRole(Role role)
{
getPk().setRole(role);
}
public boolean equals(Object o)
{
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
AccountRole that = (AccountRole) o;
if (getPk() != null ? !getPk().equals(that.getPk()) : that.getPk() != null)
return false;
return true;
}
public int hashCode()
{
return (getPk() != null ? getPk().hashCode() : 0);
}
// Other getter & setter API's
}
package sample.hibernate;
@Embeddable
public class AccountRolePk implements Serializable {
private Account account;
private Role role;
@ManyToOne
public Account getAccount() {
return account;
}
public void setAccount(Account account) {
this.account = account;
}
@ManyToOne
public Role getRole() {
return role;
}
public void setRole(Role role) {
this.role = role;
}
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AccountRolePk that = (AccountRolePk) o;
if (account != null ? !account.equals(that.account) : that.account != null) return false;
if (role != null ? !role.equals(that.role) : that.role != null)
return false;
return true;
}
public int hashCode() {
int result;
result = (account != null ? account.hashCode() : 0);
result = 31 * result + (role != null ? role.hashCode() : 0);
return result;
}
}
Hoping for some geek to help ASAP.
Thanks.