本文介绍了在EJB 3中使用appclient jar的异常:javax.ejb.EJBException:java.rmi.MarshalException:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图学习ejb 3,并在下面提到的情况下面对一个我无法解决的问题。


  1. 我有一个Entity(Book)来存储书籍相关的数据。

  2. 我创建了Stateless Bean和Remote接口并在glassfish 4中部署了jar。
  3. 基本应用程序连接到一个主要方法,我需要使用appclient获取书籍的详细信息。在这里,我收到一个错误javax.ejb.EJBException:java.rmi.MarshalException:

请看下面的代码片段更多细节。

Book.java:

  package bookstore.model ; 

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQuery;

@Entity
@NamedQuery(name =findAllBooks,query =从b书中选择b)
public class Book {

@ Id
@GeneratedValue
私人长ID;
@Column(nullable = false)
私有字符串标题;
私人浮动价格;
@Column(长度= 2000)
私有字符串描述;
private String isbn;
私人整数nbOfPage;
私人布尔插图;
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name =tag)
@Column(name =Value)
private List< String>标签;

公开列表< String> getTags(){
返回标签;
}

public void setTags(List< String> tags){
this.tags = tags;
}

public long getId(){
return id;
}

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

public String getTitle(){
return title;
}

public void setTitle(String title){
this.title = title;
}

public Float getPrice(){
return price;
}

public void setPrice(Float price){
this.price = price;
}

public String getDescription(){
return description;
}

public void setDescription(String description){
this.description = description;
}

public String getIsbn(){
return isbn;
}

public void setIsbn(String isbn){
this.isbn = isbn;
}

public Integer getNbOfPage(){
return nbOfPage;
}

public void setNbOfPage(Integer nbOfPage){
this.nbOfPage = nbOfPage;
}

public Boolean getIllustrations(){
return illustrations;
}

public void setIllustrations(布尔插图){
this.illustrations =插图;
}
}

BookEJBRemote.java:

  package bookstore.controller; 

import java.util.List;

import javax.ejb.Remote;

导入bookstore.model.Book;

@Remote
public interface BookEJBRemote {

public List< Book> findBooks();

public Book findBookById(long id);

public book create book(Book book);

public Book deleteBook(Book book);

public Book updateBook(Book book);


$ / code>

BookEJB.java:
package bookstore.controller ;

  import java.util.List; 

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

导入bookstore.model.Book;

@Stateless
@LocalBean
public class BookEJB implements BookEJBRemote {

@PersistenceContext(unitName =bookstore_persistence)
private EntityManager em ;
$ b $ *(非Javadoc)
*参见bookstore.controller.BookEJBRemote#findBooks()
* /
public List< Book> findBooks(){
TypedQuery< Book> query = em
.createNamedQuery(findAllBooks,Book.class);
返回query.getResultList();

$ b $ *(非Javadoc)
* see bookstore.controller.BookEJBRemote#findBookById(long)
* /
public Book findBookById (long id){
return em.find(Book.class,id);

$ b $ *(非Javadoc)
*参见bookstore.controller.BookEJBRemote#createBook(bookstore.model.Book)
* /
书公共图书createBook(图书){
em.persist(book);
返还书;

$ b $ *(非Javadoc)
*参见bookstore.controller.BookEJBRemote#deleteBook(bookstore.model.Book)
* /
书公共图书deleteBook(图书){
em.remove(book);
返还书;

$ b $ *(非Javadoc)
*请参阅bookstore.controller.BookEJBRemote#updateBook(bookstore.model.Book)
* /
书公共图书updateBook(书){

return em.merge(book);


persistence.xml:

 <?xml version =1.0encoding =UTF-8?> 
< persistence 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
version =2.0>
< persistence-unit name =bookstore_persistence
transaction-type =JTA>
< provider> org.eclipse.persistence.jpa.PersistenceProvider< / provider>
< jta-data-source> jdbc / mysqlPool< / jta-data-source>
< class> bookstore.model.Book< / class>
<属性>
< property name =eclipselink.target-databasevalue =MYSQL/>
< property name =eclipselink.ddl-generationvalue =drop-and-create-tables/>
< property name =eclipselink.logging-levelvalue =INFO/>
<! - property name =javax.persistence.jdbc.drivervalue =com.mysql.jdbc.Driver/>
< property name =javax.persistence.jdbc.urlvalue =jdbc:mysql:// localhost:3306 / testdb/>
< property name =javax.persistence.jdbc.uservalue =test_user/>
< property name =javax.persistence.jdbc.passwordvalue =password/ - >
< / properties>
< / persistence-unit>
< /余辉>

pom.xml:

 < project xmlns =http://maven.apache.org/POM/4.0.0xmlns:xsi =http://www.w3.org/2001/XMLSchema-instance 
xsi:schemaLocation =http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">
< modelVersion> 4.0.0< / modelVersion>
< groupId> org.sambaran< / groupId>
< artifactId>书店< / artifactId>
< version> 1.0.1-SNAPSHOT< / version>
<名称>样本书店< /名称>
<依赖关系>
< dependency>
< groupId> org.eclipse.persistence< / groupId>
< artifactId> javax.persistence< / artifactId>
< version> 2.0.0< / version>
< /依赖关系>
<! - <依赖关系> <&的groupId GT; org.eclipse.persistence< /&的groupId GT; < artifactId的>&的EclipseLink LT; / artifactId的>
< scope>运行时< / scope> <版本> 2.6.0< /版本> < /依赖性> <依赖性>
< groupId> mysql< / groupId> < artifactId的> MySQL的连接器的Java< / artifactId的> <版本> 5.1.35< /版本>
< /依赖关系> - >
< dependency>
< groupId> junit< / groupId>
< artifactId> junit< / artifactId>
< version> 4.12< / version>
< /依赖关系>
< dependency>
< groupId> org.glassfish< / groupId>
< artifactId> javax.ejb< / artifactId>
< version> 3.0.1< / version>
< /依赖关系>
< dependency>
< groupId> org.glassfish.extras< / groupId>
< artifactId> glassfish-embedded-all< / artifactId>
< version> 3.0.1< / version>
< /依赖关系>
< /依赖关系>
< build>
< plugins>
< plugin>
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-jar-plugin< / artifactId>
< version> 2.2< / version>
<配置>
<档案>
< manifest>
< mainClass> bookstore.client.BookStoreMain< / mainClass>
< / manifest>
< / archive>
< / configuration>
< / plugin>
< / plugins>
< / build>
< / project>

主类BookstoreMain.java

  package bookstore.client; 

import java.util.ArrayList;

import javax.ejb.EJB;

导入bookstore.controller.BookEJBRemote;
导入bookstore.model.Book;


public class BookStoreMain {
@EJB
private static BookEJBRemote bookEJB;
public static void main(String [] args){
// TODO自动生成的方法存根

Book book = new Book();
book.setTitle(Head First Servlets and JSP);
book.setDescription(A brain friendly guide。);
book.setIllustrations(true);
book.setIsbn(1-3244-3237676);
book.setPrice(new Float(400.00));
book.setNbOfPage(865);
ArrayList< String> tags = new ArrayList< String>();
tags.add(java);
tags.add(J2SE);
book.setTags(tags);
bookEJB.createBook(book);
book.setTitle(听第一个SQL);
bookEJB.updateBook(book);
// bookEJB
}

}

使用asadmin命令成功部署ejb。请检查以下详情。

  sambaran @ sambaran-home:〜/ glassfish-4.1 / glassfish / bin $ ./asadmin list -applications --type ejb 
bookstore-1.0.1-SNAPSHOT< ejb>


命令列表 - 应用程序已成功执行。

当我尝试使用appclient安装客户端时,它出现提到的错误。 PFB详细信息。

  sambaran @ sambaran-home:〜/ glassfish-4.1 / glassfish / bin $ ./appclient -client / home /sambaran/workspace/bookstore/target/bookstore-1.0.1-SNAPSHOT.jar 
线程main中的异常javax.ejb.EJBException:java.rmi.MarshalException:CORBA MARSHAL 1330446343否;嵌套的异常是:
org.omg.CORBA.MARSHAL:---------- BEGIN服务器端堆栈跟踪----------
org.omg。 CORBA.MARSHAL:FINE:00810007:在消息中的最后一个片段之后的BufferManagerReadStream中下溢vmcid:OMG次要代码:7已完成:否$ com
在com.sun.proxy $ Proxy167.endOfStream(未知源)
at com.sun.corba.ee.impl.encoding.BufferManagerReadStream.underflow(BufferManagerReadStream.java:122)
at com.sun.corba.ee.impl.encoding.CDRInputStream_1_1.grow(CDRInputStream_1_1.java:111)
at com.sun.corba.ee.impl.encoding.CDRInputStream_1_2.alignAndCheck(CDRInputStream_1_2.java:126)
at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_long(CDRInputStream_1_0.java :433)
at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.readValueTag(CDRInputStream_1_0.java:1672)
at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_value (CDRInputStream_1_0.java:918)
在com.sun.corba.ee.impl.encoding.CDRInputObject。 read_value(CDRInputObject.java:518)
at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl $ 14.read(DynamicMethodMarshallerImpl.java:383)
at com.sun.corba.ee .impl.presentation.rmi.DynamicMethodMarshallerImpl.readArguments(DynamicMethodMarshallerImpl.java:450)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:171)
com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatchToServant(ServerRequestDispatcherImpl.java:528)
at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatch(ServerRequestDispatcherImpl.java:199)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequestRequest(MessageMediatorImpl.java:1549)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl。 java:1425)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleInput(MessageMediatorImpl.java:930)
at com.sun.corba.ee.impl.prot ocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:213)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:694)
at com.sun。 corba.ee.impl.protocol.MessageMediatorImpl.dispatch(MessageMediatorImpl.java:496)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.doWork(MessageMediatorImpl.java:2222)
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl $ WorkerThread.performWork(ThreadPoolImpl.java:497)
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl $ WorkerThread.run(ThreadPoolImpl.java :540)

---------- END服务器端堆栈跟踪---------- vmcid:OMG次要代码:7已完成:否$ b $在bookstore.client.BookStoreMain.main(BookStoreMain.java:28)上

引起:java.rmi.MarshalException: CORBA MARSHAL 1330446343否;嵌套的异常是:
org.omg.CORBA.MARSHAL:---------- BEGIN服务器端堆栈跟踪----------
org.omg。 CORBA.MARSHAL:FINE:00810007:在消息中的最后一个片段之后的BufferManagerReadStream中下溢vmcid:OMG次要代码:7已完成:否$ com
在com.sun.proxy $ Proxy167.endOfStream(未知源)
at com.sun.corba.ee.impl.encoding.BufferManagerReadStream.underflow(BufferManagerReadStream.java:122)
at com.sun.corba.ee.impl.encoding.CDRInputStream_1_1.grow(CDRInputStream_1_1.java:111)
at com.sun.corba.ee.impl.encoding.CDRInputStream_1_2.alignAndCheck(CDRInputStream_1_2.java:126)
at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_long(CDRInputStream_1_0.java :433)
at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.readValueTag(CDRInputStream_1_0.java:1672)
at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_value (CDRInputStream_1_0.java:918)
在com.sun.corba.ee.impl.encoding.CDRInputObject。 read_value(CDRInputObject.java:518)
at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl $ 14.read(DynamicMethodMarshallerImpl.java:383)
at com.sun.corba.ee .impl.presentation.rmi.DynamicMethodMarshallerImpl.readArguments(DynamicMethodMarshallerImpl.java:450)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:171)
com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatchToServant(ServerRequestDispatcherImpl.java:528)
at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatch(ServerRequestDispatcherImpl.java:199)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequestRequest(MessageMediatorImpl.java:1549)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl。 java:1425)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleInput(MessageMediatorImpl.java:930)
at com.sun.corba.ee.impl.prot ocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:213)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:694)
at com.sun。 corba.ee.impl.protocol.MessageMediatorImpl.dispatch(MessageMediatorImpl.java:496)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.doWork(MessageMediatorImpl.java:2222)
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl $ WorkerThread.performWork(ThreadPoolImpl.java:497)
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl $ WorkerThread.run(ThreadPoolImpl.java :540)

---------- END服务器端堆栈跟踪---------- vmcid:OMG次要代码:7完成:否
at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.mapSystemException(Util.java:266)
at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.privateInvoke (StubInvocationHandlerImpl.java:211)
at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.invoke( StubInvocationHandlerImpl.java:150)
at com.sun.corba.ee.impl.presentation.rmi.codegen.CodegenStubBase.invoke(CodegenStubBase.java:226)
at bookstore.controller .__ BookEJBRemote_Remote_DynamicStub.createBook(书店/控制器/ __ BookEJBRemote_Remote_DynamicStub.java)
... 2 more
引起:org.omg.CORBA.MARSHAL:---------- BEGIN服务器端堆栈跟踪 - --------
org.omg.CORBA.MARSHAL:FINE:00810007:在消息中的最后一个片段之后在BufferManagerReadStream中下溢vmcid:OMG次要代码:7已完成:没有
在com.sun .proxy。$ Proxy167.endOfStream(Unknown Source)
at com.sun.corba.ee.impl.encoding.BufferManagerReadStream.underflow(BufferManagerReadStream.java:122)
at com.sun.corba.ee .impl.encoding.CDRInputStream_1_1.grow(CDRInputStream_1_1.java:111)
at com.sun.corba.ee.impl.encoding.CDRInputStream_1_2.alignAndCheck(CDRInputStream_1_2.java:126)
at com.sun .corba.ee.impl.encoding.CDRInputStream_1_0.read_long(CDRI (com.un.corba.ee.impl.encoding.CDRInputStream_1_0.readValueTag(CDRInputStream_1_0.java:1672)
at com.sun.corba.ee.impl.encoding。 CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:918)
at com.sun.corba.ee.impl.encoding.CDRInputObject.read_value(CDRInputObject.java:518)
at com.sun.corba.ee。 impl.presentation.rmi.DynamicMethodMarshallerImpl $ 14.read(DynamicMethodMarshallerImpl.java:383)
at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl.readArguments(DynamicMethodMarshallerImpl.java:450)
com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:171)
at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatchToServant(ServerRequestDispatcherImpl.java: 528)
at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatch(ServerRequestDispatcherImpl.java:199)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest Request(MessageMediatorImpl.java:1549)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:1425)
at com.sun.corba.ee.impl。 protocol.MessageMediatorImpl.handleInput(MessageMediatorImpl.java:930)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:213)
at com.sun。 corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:694)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.dispatch(MessageMediatorImpl.java:496)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.doWork(MessageMediatorImpl.java:2222)
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl $ WorkerThread.performWork(ThreadPoolImpl.java:497 )
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl $ WorkerThread.run(ThreadPoolImpl.java:540)

END服务器侧面堆栈跟踪---------- vmcid:OMG次要代码:7完成:否
a牛逼sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)美元,sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)B
$ b。在sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.MessageBase.getSystemException(MessageBase.java:813)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.ReplyMessage_1_2.getSystemException(ReplyMessage_1_2.java:131)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.getSystemExceptionReply( MessageMediatorImpl.java:594)
at com.sun.corba.ee.impl.protocol.ClientRequestDispatcherImpl.processResponse(ClientRequestDispatcherImpl.java:518)
at com.sun.corba.ee.impl.protocol。 ClientRequestDispatcherImpl.marshalingComplete(ClientRequestDispatcherImpl.java:392)
at com.sun.corba.ee.imp l.protocol.ClientDelegateImpl.invoke(ClientDelegateImpl.java:258)
at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.privateInvoke(StubInvocationHandlerImpl.java:198)
... 5 more


解决方案

它看起来像您的实体类不是序列化,在 Book class

中实现 Serializable 接口

<$ p $ (
$ b $)
$ b $ {
$ @ $ b @Id
@GeneratedValue
私人长ID;

...

}

希望这将有所帮助。


I am trying to learn ejb 3 and facing an issue in the below mentioned scenario which I am not able to figure out.

  1. I am having one Entity (Book) to store book related data.
  2. I have created Stateless Bean and Remote interfaces and deployed the jar in glassfish 4.
  3. The basic application connects to a main method where I need to get the details of the book using appclient. Here I am getting an error "javax.ejb.EJBException: java.rmi.MarshalException:"

Please look into the below snippets for more details.

Book.java:

package bookstore.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQuery;

@Entity
@NamedQuery(name = "findAllBooks", query = "select b from Book b")
public class Book {

@Id
@GeneratedValue
private long id;
@Column(nullable = false)
private String title;
private Float price;
@Column(length = 2000)
private String description;
private String isbn;
private Integer nbOfPage;
private Boolean illustrations;
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "tag")
@Column(name = "Value")
private List<String> tags;

public List<String> getTags() {
    return tags;
}

public void setTags(List<String> tags) {
    this.tags = tags;
}

public long getId() {
    return id;
}

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

public String getTitle() {
    return title;
}

public void setTitle(String title) {
    this.title = title;
}

public Float getPrice() {
    return price;
}

public void setPrice(Float price) {
    this.price = price;
}

public String getDescription() {
    return description;
}

public void setDescription(String description) {
    this.description = description;
}

public String getIsbn() {
    return isbn;
}

public void setIsbn(String isbn) {
    this.isbn = isbn;
}

public Integer getNbOfPage() {
    return nbOfPage;
}

public void setNbOfPage(Integer nbOfPage) {
    this.nbOfPage = nbOfPage;
}

public Boolean getIllustrations() {
    return illustrations;
}

public void setIllustrations(Boolean illustrations) {
    this.illustrations = illustrations;
}
}

BookEJBRemote.java:

package bookstore.controller;

import java.util.List;

import javax.ejb.Remote;

import bookstore.model.Book;

@Remote
public interface BookEJBRemote {

    public List<Book> findBooks();

    public Book findBookById(long id);

    public Book createBook(Book book);

    public Book deleteBook(Book book);

    public Book updateBook(Book book);

}

BookEJB.java: package bookstore.controller;

import java.util.List;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import bookstore.model.Book;

@Stateless
@LocalBean
public class BookEJB implements BookEJBRemote {

    @PersistenceContext(unitName = "bookstore_persistence")
    private EntityManager em;

    /* (non-Javadoc)
     * @see bookstore.controller.BookEJBRemote#findBooks()
     */
    public List<Book> findBooks() {
        TypedQuery<Book> query = em
                .createNamedQuery("findAllBooks", Book.class);
        return query.getResultList();
    }

    /* (non-Javadoc)
     * @see bookstore.controller.BookEJBRemote#findBookById(long)
     */
    public Book findBookById(long id) {
        return em.find(Book.class, id);
    }

    /* (non-Javadoc)
     * @see bookstore.controller.BookEJBRemote#createBook(bookstore.model.Book)
     */
    public Book createBook(Book book) {
        em.persist(book);
        return book;
    }

    /* (non-Javadoc)
     * @see bookstore.controller.BookEJBRemote#deleteBook(bookstore.model.Book)
     */
    public Book deleteBook(Book book) {
        em.remove(book);
        return book;
    }

    /* (non-Javadoc)
     * @see bookstore.controller.BookEJBRemote#updateBook(bookstore.model.Book)
     */
    public Book updateBook(Book book) {

        return em.merge(book);
    }
}

persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence 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"
    version="2.0">
    <persistence-unit name="bookstore_persistence"
        transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>jdbc/mysqlPool</jta-data-source>
        <class>bookstore.model.Book</class>
        <properties>
            <property name="eclipselink.target-database" value="MYSQL" />
            <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
            <property name="eclipselink.logging-level" value="INFO" />
            <!--  property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/testdb" />
            <property name="javax.persistence.jdbc.user" value="test_user" />
            <property name="javax.persistence.jdbc.password" value="password" /-->
        </properties>
    </persistence-unit>
</persistence>

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.sambaran</groupId>
    <artifactId>bookstore</artifactId>
    <version>1.0.1-SNAPSHOT</version>
    <name>sample-bookstore</name>
    <dependencies>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>javax.persistence</artifactId>
            <version>2.0.0</version>
        </dependency>
        <!-- <dependency> <groupId>org.eclipse.persistence</groupId> <artifactId>eclipselink</artifactId>
            <scope>runtime</scope> <version>2.6.0</version> </dependency> <dependency>
            <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.35</version>
            </dependency> -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.ejb</artifactId>
            <version>3.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.extras</groupId>
            <artifactId>glassfish-embedded-all</artifactId>
            <version>3.0.1</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>bookstore.client.BookStoreMain</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Main class BookstoreMain.java

package bookstore.client;

import java.util.ArrayList;

import javax.ejb.EJB;

import bookstore.controller.BookEJBRemote;
import bookstore.model.Book;


public class BookStoreMain {
    @EJB
    private static BookEJBRemote bookEJB;
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        Book book = new Book();
        book.setTitle("Head First Servlets and JSP");
        book.setDescription("A brain friendly guide.");
        book.setIllustrations(true);
        book.setIsbn("1-3244-3237676");
        book.setPrice(new Float(400.00));
        book.setNbOfPage(865);
        ArrayList<String> tags = new ArrayList<String>();
        tags.add("java");
        tags.add("J2SE");
        book.setTags(tags);
        bookEJB.createBook(book);
        book.setTitle("Hear First SQL");
        bookEJB.updateBook(book);
        //bookEJB
    }

}

Deployment of ejb was successful using asadmin command. Please check the details below.

sambaran@sambaran-home:~/glassfish-4.1/glassfish/bin$ ./asadmin list-applications --type ejb
bookstore-1.0.1-SNAPSHOT  <ejb>


Command list-applications executed successfully.

When I try to use appclient to install the client it is having the mentioned error. PFB details.

sambaran@sambaran-home:~/glassfish-4.1/glassfish/bin$ ./appclient -client  /home/sambaran/workspace/bookstore/target/bookstore-1.0.1-SNAPSHOT.jar
Exception in thread "main" javax.ejb.EJBException: java.rmi.MarshalException: CORBA MARSHAL 1330446343 No; nested exception is:
    org.omg.CORBA.MARSHAL: ----------BEGIN server-side stack trace----------
org.omg.CORBA.MARSHAL: FINE: 00810007: Underflow in BufferManagerReadStream after last fragment in message  vmcid: OMG  minor code: 7  completed: No
    at com.sun.proxy.$Proxy167.endOfStream(Unknown Source)
    at com.sun.corba.ee.impl.encoding.BufferManagerReadStream.underflow(BufferManagerReadStream.java:122)
    at com.sun.corba.ee.impl.encoding.CDRInputStream_1_1.grow(CDRInputStream_1_1.java:111)
    at com.sun.corba.ee.impl.encoding.CDRInputStream_1_2.alignAndCheck(CDRInputStream_1_2.java:126)
    at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_long(CDRInputStream_1_0.java:433)
    at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.readValueTag(CDRInputStream_1_0.java:1672)
    at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:918)
    at com.sun.corba.ee.impl.encoding.CDRInputObject.read_value(CDRInputObject.java:518)
    at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl$14.read(DynamicMethodMarshallerImpl.java:383)
    at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl.readArguments(DynamicMethodMarshallerImpl.java:450)
    at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:171)
    at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatchToServant(ServerRequestDispatcherImpl.java:528)
    at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatch(ServerRequestDispatcherImpl.java:199)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequestRequest(MessageMediatorImpl.java:1549)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:1425)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleInput(MessageMediatorImpl.java:930)
    at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:213)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:694)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.dispatch(MessageMediatorImpl.java:496)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.doWork(MessageMediatorImpl.java:2222)
    at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497)
    at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540)

----------END server-side stack trace----------  vmcid: OMG  minor code: 7  completed: No
    at bookstore.controller._BookEJBRemote_Wrapper.createBook(bookstore/controller/_BookEJBRemote_Wrapper.java)
    at bookstore.client.BookStoreMain.main(BookStoreMain.java:28)
Caused by: java.rmi.MarshalException: CORBA MARSHAL 1330446343 No; nested exception is:
    org.omg.CORBA.MARSHAL: ----------BEGIN server-side stack trace----------
org.omg.CORBA.MARSHAL: FINE: 00810007: Underflow in BufferManagerReadStream after last fragment in message  vmcid: OMG  minor code: 7  completed: No
    at com.sun.proxy.$Proxy167.endOfStream(Unknown Source)
    at com.sun.corba.ee.impl.encoding.BufferManagerReadStream.underflow(BufferManagerReadStream.java:122)
    at com.sun.corba.ee.impl.encoding.CDRInputStream_1_1.grow(CDRInputStream_1_1.java:111)
    at com.sun.corba.ee.impl.encoding.CDRInputStream_1_2.alignAndCheck(CDRInputStream_1_2.java:126)
    at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_long(CDRInputStream_1_0.java:433)
    at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.readValueTag(CDRInputStream_1_0.java:1672)
    at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:918)
    at com.sun.corba.ee.impl.encoding.CDRInputObject.read_value(CDRInputObject.java:518)
    at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl$14.read(DynamicMethodMarshallerImpl.java:383)
    at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl.readArguments(DynamicMethodMarshallerImpl.java:450)
    at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:171)
    at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatchToServant(ServerRequestDispatcherImpl.java:528)
    at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatch(ServerRequestDispatcherImpl.java:199)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequestRequest(MessageMediatorImpl.java:1549)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:1425)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleInput(MessageMediatorImpl.java:930)
    at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:213)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:694)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.dispatch(MessageMediatorImpl.java:496)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.doWork(MessageMediatorImpl.java:2222)
    at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497)
    at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540)

----------END server-side stack trace----------  vmcid: OMG  minor code: 7  completed: No
    at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.mapSystemException(Util.java:266)
    at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.privateInvoke(StubInvocationHandlerImpl.java:211)
    at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.invoke(StubInvocationHandlerImpl.java:150)
    at com.sun.corba.ee.impl.presentation.rmi.codegen.CodegenStubBase.invoke(CodegenStubBase.java:226)
    at bookstore.controller.__BookEJBRemote_Remote_DynamicStub.createBook(bookstore/controller/__BookEJBRemote_Remote_DynamicStub.java)
    ... 2 more
Caused by: org.omg.CORBA.MARSHAL: ----------BEGIN server-side stack trace----------
org.omg.CORBA.MARSHAL: FINE: 00810007: Underflow in BufferManagerReadStream after last fragment in message  vmcid: OMG  minor code: 7  completed: No
    at com.sun.proxy.$Proxy167.endOfStream(Unknown Source)
    at com.sun.corba.ee.impl.encoding.BufferManagerReadStream.underflow(BufferManagerReadStream.java:122)
    at com.sun.corba.ee.impl.encoding.CDRInputStream_1_1.grow(CDRInputStream_1_1.java:111)
    at com.sun.corba.ee.impl.encoding.CDRInputStream_1_2.alignAndCheck(CDRInputStream_1_2.java:126)
    at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_long(CDRInputStream_1_0.java:433)
    at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.readValueTag(CDRInputStream_1_0.java:1672)
    at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:918)
    at com.sun.corba.ee.impl.encoding.CDRInputObject.read_value(CDRInputObject.java:518)
    at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl$14.read(DynamicMethodMarshallerImpl.java:383)
    at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl.readArguments(DynamicMethodMarshallerImpl.java:450)
    at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:171)
    at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatchToServant(ServerRequestDispatcherImpl.java:528)
    at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatch(ServerRequestDispatcherImpl.java:199)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequestRequest(MessageMediatorImpl.java:1549)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:1425)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleInput(MessageMediatorImpl.java:930)
    at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:213)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:694)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.dispatch(MessageMediatorImpl.java:496)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.doWork(MessageMediatorImpl.java:2222)
    at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497)
    at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540)

----------END server-side stack trace----------  vmcid: OMG  minor code: 7  completed: No
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at com.sun.corba.ee.impl.protocol.giopmsgheaders.MessageBase.getSystemException(MessageBase.java:813)
    at com.sun.corba.ee.impl.protocol.giopmsgheaders.ReplyMessage_1_2.getSystemException(ReplyMessage_1_2.java:131)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.getSystemExceptionReply(MessageMediatorImpl.java:594)
    at com.sun.corba.ee.impl.protocol.ClientRequestDispatcherImpl.processResponse(ClientRequestDispatcherImpl.java:518)
    at com.sun.corba.ee.impl.protocol.ClientRequestDispatcherImpl.marshalingComplete(ClientRequestDispatcherImpl.java:392)
    at com.sun.corba.ee.impl.protocol.ClientDelegateImpl.invoke(ClientDelegateImpl.java:258)
    at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.privateInvoke(StubInvocationHandlerImpl.java:198)
    ... 5 more
解决方案

it looks like your entity class is not serialize, implement Serializable interface in your Book class

@Entity
@NamedQuery(name = "findAllBooks", query = "select b from Book b")
public class Book implements Serializable {

@Id
@GeneratedValue
private long id;

...

}

hope it will help.

这篇关于在EJB 3中使用appclient jar的异常:javax.ejb.EJBException:java.rmi.MarshalException:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 17:56