2

我在 netbeans 中创建了一个 java web 项目,我创建了我的实体 bean,然后部署了我的项目来生成我的数据库,这项工作是成功的。

然后我生成了会话 bean 来访问创建的数据库。我创建了一个主类来测试会话 bean,当我测试通过会话 bean 接口调用的方法“find”时,我注意到一些类抛出异常,并且我注意到带有 vars List 的实体类抛出好像它们无法序列化的异常。

我想给我带来实体列表是一个请求。

我在同一个项目中拥有实体 bean,该项目具有我的会话 bean,在 Web 应用程序中......

我使用 Glass Fish 3.1.2
Netbeans 7.1.2
EclipseLink 2.0

实体持久性是:

@Entity

public class UserApplication implements Serializable {

private static long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idUserApplication;
@Basic(optional=false)
@Column(nullable=false)
private String dcn;
@Basic(optional=false)
@Column(nullable=false)
private String password;
@Basic(optional=false)
@Column(nullable=false)
private String title ;
@Basic(optional=false)
@Column(nullable=false)
private String firstName;
@Basic(optional=false)
@Column(nullable=false)
private String lastName;
@Basic(optional=false)
@Column(nullable=false)
private String ci;
@Basic(optional=false)
@Column(nullable=false)
private String personalEmail;
@Basic(optional=false)
@Column(nullable=false)
private String workEmail;

@OneToMany
@JoinColumn(name = "userApplication_id", nullable = false)
private List<Account> accounts;
@OneToMany
@JoinColumn(name = "userApplication_id", nullable = true)
private List<CreditCard> creditCards = null;

@ManyToMany
@JoinTable(name="UserApplication_BeneficiaryThird", joinColumns=@JoinColumn
        (name="userApplication_id", nullable = false), inverseJoinColumns=
        @JoinColumn(name="beneficiaryThird_id", nullable = false))
private List<BeneficiaryThird> beneficiariesThird = null;

@OneToMany
@JoinColumn(name = "userApplication_id_beneficiary", nullable = true)
private List<BeneficiaryBankItself> beneficiariesBankItself = null;

@ManyToMany
@JoinTable(name="UserApplication_TransactionRule", joinColumns=@JoinColumn
        (name="userApplication_id", nullable = false), inverseJoinColumns=
        @JoinColumn(name="transactionRule_id", nullable = false))
private List<TransactionRule> transactionRules = null;

@OneToOne(mappedBy = "userApplication", optional = true, cascade = CascadeType.ALL)
private SessionCookie cookieId = null;................

主类是:

public class Main {

public static void main(String[] args) {

    long id = 2;


    bank.setId(id);
    UserApplication userApplication = GetBean.getUserFacade().find(id);
    System.out.println("user: " + userApplication.getFirstName());


    }

}

GetBean 是实用程序类,是:

public class GetBean {



public static BankFacadeLocal getBankFacade() {

    BankFacadeLocal bankFacade = null;
    String jndiName = beans.BankFacadeLocal.class.getName();
    try {
         //bankFacade = (BankFacadeLocal) new InitialContext().lookup("java:global/IntegrationBanking/BankFacade!sessionBeans.BankFacadeLocal");
          bankFacade = (BankFacadeLocal) new InitialContext().lookup(jndiName);        
    } catch (NamingException ex) {
        Logger.getLogger(GetBean.class.getName()).log(Level.SEVERE, null, ex);
    }

    return bankFacade;
 }

 public static UserApplicationFacadeLocal getUserFacade() {

    UserApplicationFacadeLocal userFacade = null;
    String jndiName = UserApplicationFacadeLocal.class.getName();
    try {
         // userFacade = (UserApplicationFacadeLocal) new InitialContext().lookup("java:global/IntegrationBanking/UserApplicationFacade!beans.UserApplicationFacadeLocal");
         userFacade = (UserApplicationFacadeLocal) new InitialContext().lookup(jndiName);        
    } catch (NamingException ex) {
        Logger.getLogger(GetBean.class.getName()).log(Level.SEVERE, null, ex);
    }

    return userFacade;
} 

}

坚持单位:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="BankingIntegrationPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>sqlServer</jta-data-source>
<properties>
  <property name="eclipselink.ddl-generation" value="create-tables"/>
</properties>
</persistence-unit>
</persistence>

例外是:

jul 26, 2012 2:55:38 PM com.sun.corba.ee.spi.orbutil.logex.WrapperGenerator handleFullLogging
Advertencia: IOP00810011: Exception from readValue on ValueHandler in CDRInputStream
org.omg.CORBA.MARSHAL: Advertencia: IOP00810011: Exception from readValue on ValueHandler in CDRInputStream  vmcid: OMG  minor code: 11 completed: Maybe
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)............
Caused by: java.io.IOException: Mismatched serialization UIDs : Source (Rep. IDRMI:entities.UserApplication:5CDFA7C871B53786:F07C8D07E21B75FA) = F07C8D07E21B75FA whereas Target (Rep. ID RMI:entities.UserApplication:4357CF2703B83ACF:180694EF6A1B61BC) = 180694EF6A1B61BC
    at com.sun.corba.ee.impl.util.RepositoryId.useFullValueDescription(RepositoryId.java:679)
    at com.sun.corba.ee.impl.util.RepositoryId.useFullValueDescription(RepositoryId.java:639)
    at com.sun.corba.ee.impl.io.ValueHandlerImpl.useFullValueDescription(ValueHandlerImpl.java:360)
    at com.sun.corba.ee.impl.io.IIOPInputStream.simpleReadObject(IIOPInputStream.java:422)........
jul 26, 2012 2:55:38 PM com.sun.corba.ee.spi.orbutil.logex.WrapperGenerator handleFullLogging
Advertencia: ORBIO00013: Stream corrupted
java.io.StreamCorruptedException: Advertencia: ORBIO00013: Stream corrupted
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)............
jul 26, 2012 2:55:38 PM com.sun.corba.ee.spi.orbutil.logex.WrapperGenerator handleFullLogging
Advertencia: IOP00810011: Exception from readValue on ValueHandler in CDRInputStream
org.omg.CORBA.MARSHAL: Advertencia: IOP00810011: Exception from readValue on ValueHandler in CDRInputStream  vmcid: OMG  minor code: 11 completed: Maybe
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)............
Caused by: java.io.StreamCorruptedException: Advertencia: ORBIO00013: Stream corrupted
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)...........
Exception in thread "main" javax.ejb.EJBException: java.rmi.MarshalException: CORBA MARSHAL 1330446347 Maybe; nested exception is: 
    org.omg.CORBA.MARSHAL: Advertencia: IOP00810011: Exception from readValue on ValueHandler in CDRInputStream  vmcid: OMG  minor code: 11 completed: Maybe
    at beans._BeneficiaryBankItselfFacadeLocal_Wrapper.find(beans/_BeneficiaryBankItselfFacadeLocal_Wrapper.java)....................
Caused by: java.rmi.MarshalException: CORBA MARSHAL 1330446347 Maybe; nested exception is: 
    org.omg.CORBA.MARSHAL: Advertencia: IOP00810011: Exception from readValue on ValueHandler in CDRInputStream  vmcid: OMG  minor code: 11 completed: Maybe
    at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.mapSystemException(Util.java:267)...........
Caused by: org.omg.CORBA.MARSHAL: Advertencia: IOP00810011: Exception from readValue on ValueHandler in CDRInputStream  vmcid: OMG  minor code: 11 completed: Maybe
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)..................
Caused by: java.io.StreamCorruptedException: Advertencia: ORBIO00013: Stream corrupted
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)....................
4

1 回答 1

2

我的回答可能不正确,但我遇到了这个问题并解决了它。对我来说,问题只是我的数据库没有连接!我在 Glassfish 中对此进行了测试,确认了数据库连接问题并修复了它,然后这个错误就消失了。

就理解为什么是我们得到的神秘错误消息而言,以下解释可能会有所帮助:

  • 首先,实体 bean(现在被使用 Java Persistence API 取代)是一种 EJB,因此在 EJB 容器中运行。
  • 您的主类存在于 EJB 容器之外,因此必须“调用”一个 EJB。它通过使用 CORBA(通用对象请求代理体系结构)来做到这一点
  • CORBA 是围绕您可以远程实例化和操作对象的想法构建的。例如,您可以创建 EJB 实例、设置其成员属性、运行其方法,所有这些都来自EJB 容器外部的 main 方法。CORBA 是理论上任何“客户端”都可以使用的通用标准(例如,进行符合 CORBA 的调用的 C++ 程序理论上可以在这里工作。但当然,Java 世界中的大多数人只是使用 CORBA 来访问EJB 容器。
  • 你得到的特定错误是ORBIO00013: Stream corrupted,我不完全理解,但我认为它的意思是你的主程序成功连接到 EJB 容器,EJB 容器抛出异常,然后返回了 CORBA 没有预料到的东西,这损坏了用于发送响应的流。
  • 真正的问题是 CORBA 没有很好地处理 EJB 中抛出的异常,因此解决此问题的唯一方法是调试程序并找到 EJB 中抛出异常的位置,然后查看异常直接在调试器中。

完成所有这些最终帮助我理解了一个简单的数据库连接问题(!)是问题所在。

希望这会有所帮助,乔希

于 2013-11-21T19:44:42.167 回答