首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 服务器 > 其他服务器 >

Jboss上使用EJB3创建一对一主键关联映射,client端访问出错!

2013-01-05 
Jboss下使用EJB3创建一对一主键关联映射,client端访问出错!!!!一:@Entity@Table(nameIdentity)public c

Jboss下使用EJB3创建一对一主键关联映射,client端访问出错!!!!
一:
@Entity
@Table(name="Identity")
public class Identity implements Serializable {

@Id
@GeneratedValue(generator="test")
@GenericGenerator(name="test", strategy="foreign", parameters=@Parameter(name="property", value="person"))
private int id;

private int number;

@OneToOne(mappedBy="identity")
private Person person;

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}


public int getNumber() {
return number;
}

public void setNumber(int number) {
this.number = number;
}

public Person getPerson() {
return person;
}

public void setPerson(Person person) {
this.person = person;
}

}

@Entity
@Table(name="person")
public class Person implements Serializable{

@Id
@GeneratedValue
private int pid;

private String name;

@OneToOne(cascade=CascadeType.ALL)
@PrimaryKeyJoinColumn
private Identity identity;

public int getPid() {
return pid;
}

public void setPid(int pid) {
this.pid = pid;
}

public Identity getIdentity() {
return identity;
}

public void setIdentity(Identity identity) {
this.identity = identity;
}

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

@Stateless
@Remote
public class PersonManagerBean implements PersonManager {

@PersistenceContext(unitName="jpa_04_one2onePU")
public EntityManager em;

public void addIdentity(Identity identity) {
em.persist(identity);

}

public void addPerson(Person person) {
em.persist(person);
}

public Person getPersonById(int id) {
return em.find(Person.class, id);
}

}

client端:
public class One2One_client {


public static void main(String[] args) {
try {
Context context = new InitialContext();

PersonManager pm = (PersonManager)context.lookup("PersonManagerBean/remote");
Identity ide = new Identity();
//ide.setId(1);
ide.setNumber(12345);
//pm.addIdentity(ide);

Person person = new Person();
person.setName("xxx");
person.setIdentity(ide);
pm.addPerson(person);

//Person person1 = pm.getPersonById(0);
//System.out.println(person1.getName());
//Identity identity = person1.getIdentity();
//System.out.println(identity.getNumber());

} catch (NamingException e) {
e.printStackTrace();
}

}

}

访问时跑出异常:
Exception in thread "main" java.lang.reflect.UndeclaredThrowableException
at $Proxy2.addPerson(Unknown Source)
at com.luc.ejb.One2One_client.main(One2One_client.java:23)
Caused by: java.lang.ClassNotFoundException: org.hibernate.id.IdentifierGenerationException


at org.jboss.remoting.serialization.ClassLoaderUtility.loadClass(ClassLoaderUtility.java:103)
at org.jboss.remoting.loading.RemotingClassLoader.loadClass(RemotingClassLoader.java:86)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at org.jboss.remoting.loading.ObjectInputStreamWithClassLoader.resolveClass(ObjectInputStreamWithClassLoader.java:179)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1575)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1496)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.receiveObjectVersion2_2(JavaSerializationManager.java:238)
at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.receiveObject(JavaSerializationManager.java:138)
at org.jboss.remoting.marshal.serializable.SerializableUnMarshaller.read(SerializableUnMarshaller.java:123)
at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.versionedRead(MicroSocketClientInvoker.java:1220)
at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.transport(MicroSocketClientInvoker.java:850)
at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:165)
at org.jboss.remoting.Client.invoke(Client.java:1724)
at org.jboss.remoting.Client.invoke(Client.java:629)
at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:60)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.ejb3.security.client.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:65)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:74)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62)
at $Proxy3.invoke(Unknown Source)
at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:207)
at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:164)
at $Proxy2.addPerson(Unknown Source)


at com.luc.ejb.One2One_client.main(One2One_client.java:23)
at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:72)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.ejb3.security.client.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:65)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:74)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62)
at $Proxy3.invoke(Unknown Source)
at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:207)
at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:164)
... 2 more
[解决办法]
你标签是否  引用的包错误 
[解决办法]
期待解决中。。。。
[解决办法]
Identity ide = new Identity();
// ide.setId(1);
ide.setNumber(12345);
// pm.addIdentity(ide);

Person person = new Person();
person.setName("xxx");
person.setIdentity(ide);
pm.addPerson(person);

==========================
以上是没定义,只能通过远程对象获得,不能私自创建

热点排行