2013-04-25 7 views
0

Iam이 ejb + JPA (최대 절전 모드) 응용 프로그램을 작업 중입니다. 데이터를 데이터베이스에 삽입 할 때 해당 데이터가 삽입되지 않습니다. 하지만 sessionbean에서 오류가 발생하지 않습니다.데이터가 데이터베이스에 저장되지 않고 예외가 발생하지 않음

아래 코드입니다.

@PersistenceContext private EntityManager em; 

    @Override 
    public void insterCustomerDetails(Customer customer) { 
     // TODO Auto-generated method stub 
     try{ 
      System.out.println("properties:::"+em.getProperties()); 
      System.out.println("Model :::"+em.getMetamodel()); 
     System.out.println("Name ::::" + customer.getName() + "::customer id ::"+customer.getCustomer_id()+"::email::"+customer.getEmail_id()+"::address::"+customer.getAddress()+ 
       ":::ph number::"+customer.getPhNumber()); 
     em.persist(customer); 
     }catch(Exception e){ 
     e.printStackTrace(); 
    } 
    } 


Beanclasse

package retail.model.vo; 

import java.io.Serializable; 

import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.GeneratedValue; 
import javax.persistence.GenerationType; 
import javax.persistence.Id; 
import javax.persistence.Table; 

@Entity 
@Table(name = "CUSTOMER") 
public class Customer implements Serializable{ 

    /** 
    * 
    */ 
    private static final long serialVersionUID = 5256938732963606407L; 
    private int customer_id; 
    private String name; 
    private String address; 
    private String email_id; 
    private int phNumber; 

    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    @Column(name = "customer_id") 
    public int getCustomer_id() { 
     return customer_id; 
    } 

    public void setCustomer_id(int customer_id) { 
     this.customer_id = customer_id; 
    } 

    @Column(name = "Name") 
    public String getName() { 
     return name; 
    } 

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

    @Column(name = "addres") 
    public String getAddress() { 
     return address; 
    } 

    public void setAddress(String address) { 
     this.address = address; 
    } 

    @Column(name = "email_add") 
    public String getEmail_id() { 
     return email_id; 
    } 

    public void setEmail_id(String email_id) { 
     this.email_id = email_id; 
    } 

    @Column(name = "ph_number") 
    public int getPhNumber() { 
     return phNumber; 
    } 

    public void setPhNumber(int phNumber) { 
     this.phNumber = phNumber; 
    } 

    public String validate(){ 
      if(name!=null && name!=""){ 
      System.out.println("chandan"); 
      return "viewCustomerDetails"; 
      } 
      else{ 
      return "viewCustomerDetails"; 
      } 
      } 
} 


ManagedBean은

public String createCustomer() throws NamingException{ 
    try{ 
    System.out.println("in Create customer method +++++++++++++++++++++++"); 
    Properties p = new Properties(); 
    //p.put("java.naming.factory.initial","com.sun.jndi.cosnaming.CNCtxFactory"); 
    p.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.impl.SerialInitContextFactory"); 
    p.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming"); 
    p.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl"); 
    p.setProperty("org.omg.CORBA.ORBInitialHost", "localhost"); 
    p.setProperty("org.omg.CORBA.ORBInitialPort", "3700"); //any configured port different from 3700 - 34513 
    InitialContext c = new InitialContext(p); 
    System.out.println("in Create customer method remote+++++++++++++++++++++++"); 
    CustomerSessionBeanRemote remote = (CustomerSessionBeanRemote) c.lookup("java:global/RetailProducts/CustomerSessionBeanImpl!retail.ejb.service.CustomerSessionBeanRemote"); 
                      //java:global/RetailService/CustomerSessionBeanImpl!retail.ejb.service.CustomerSessionBeanRemote 
    //java:global/RetailProducts/CustomerSessionBeanImpl!retail.ejb.service.CustomerSessionBeanRemote 
    System.out.println("in Create customer method remote222+++++++++++++++++++++++"); 
    remote.insterCustomerDetails(getCustomer()); 
    remote.showCustDetails(); 
    }catch(Exception e){ 
     e.printStackTrace(); 
    } 
    //System.exit(1); 
    return "viewCustomerDetails"; 
} 

,321 0의 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_1_0.xsd" 
    version="1.0"> 

    <persistence-unit name="RetailUnit" > 
     <provider>org.hibernate.ejb.HibernatePersistence</provider> 
     <!-- the JNDI data source--> 
     <jta-data-source>java/customer</jta-data-source> 
     <properties> 
      <!-- if this is true, hibernate will print (to stdout) the SQL it executes, 
       so you can check it to ensure it's not doing anything crazy 
       <property name="hibernate.connection.driver_class" value="org.apache.derby.jdbc.ClientDriver"/> 
       <property name="hibernate.connection.url" value="jdbc:derby://localhost:1527/company;create=true" /> 
       <property name="hibernate.connection.username" value="user" /> 
       <property name="hibernate.connection.password" value="123" /> --> 
      <property name="hibernate.show_sql" value="true" /> 
      <property name="hibernate.format_sql" value="true" /> 
      <!-- since most database servers have slightly different versions of the 
       SQL, Hibernate needs you to choose a dialect so it knows the subtleties of 
       talking to that server --> 
      <property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect" /> 
      <property name="hibernate.archive.autodetection" value="class"/> 
      <!-- this tell Hibernate to update the DDL when it starts, very useful 
       for development, dangerous in production --> 
      <property name="hibernate.hbm2ddl.auto" value="create" /> 
     </properties> 
    </persistence-unit> 
</persistence> 


여기서 I는 그것이 삽입 또는 Derby 데이터베이스 툴의 커맨드를 사용 여부 데이터베이스 체크 콘솔 출력

INFO: Name ::::sdasdas::customer id ::0::email::sdasdasd::address::asdasdasd:::ph number::2323234 
INFO: Hibernate: 
    insert 
    into 
     CUSTOMER 
     (customer_id, addres, email_add, Name, ph_number) 
    values 
     (default, ?, ?, ?, ?) 
INFO: Hibernate: 

values 
    identity_val_local() 


에게이다. 고객 테이블에 행이 없습니다.

아무에게도 도움을주세요.

업데이트 :

이제 점점 예외입니다.

SEVERE: java.lang.IllegalStateException: A JTA EntityManager cannot use getTransaction() 
    at org.hibernate.ejb.AbstractEntityManagerImpl.getTransaction(AbstractEntityManagerImpl.java:985) 
    at com.sun.enterprise.container.common.impl.EntityManagerWrapper.getTransaction(EntityManagerWrapper.java:857) 
    at retail.ejb.service.CustomerSessionBeanImpl.insterCustomerDetails(CustomerSessionBeanImpl.java:24) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:601) 
    at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052) 
    at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124) 
    at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5388) 
    at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:619) 
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800) 
    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571) 
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:162) 
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:144) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:601) 
    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861) 
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800) 
    at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:370) 
    at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5360) 
    at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5348) 
    at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:206) 
    at com.sun.ejb.containers.EJBObjectInvocationHandlerDelegate.invoke(EJBObjectInvocationHandlerDelegate.java:79) 
    at $Proxy255.insterCustomerDetails(Unknown Source) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:601) 
    at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.privateInvoke(StubInvocationHandlerImpl.java:241) 
    at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.invoke(StubInvocationHandlerImpl.java:152) 
    at com.sun.corba.ee.impl.presentation.rmi.codegen.CodegenStubBase.invoke(CodegenStubBase.java:227) 
    at retail.ejb.service.__CustomerSessionBeanRemote_Remote_DynamicStub.insterCustomerDetails(retail/ejb/service/__CustomerSessionBeanRemote_Remote_DynamicStub.java) 
    at retail.ejb.service._CustomerSessionBeanRemote_Wrapper.insterCustomerDetails(retail/ejb/service/_CustomerSessionBeanRemote_Wrapper.java) 
    at retail.web.mbean.CustomerMB.createCustomer(CustomerMB.java:58) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:601) 
    at com.sun.el.parser.AstValue.invoke(AstValue.java:254) 
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:302) 
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88) 
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102) 
    at javax.faces.component.UICommand.broadcast(UICommand.java:315) 
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794) 
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259) 
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) 
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) 
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) 
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) 
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) 
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655) 
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161) 
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231) 
    at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317) 
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195) 
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860) 
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757) 
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056) 
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229) 
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) 
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) 
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) 
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) 
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) 
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) 
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71) 
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) 
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) 
    at java.lang.Thread.run(Thread.java:722) 
+0

빈에서 프로그래밍 방식으로 트랜잭션 객체를 얻고 있습니까? 전체 빈 코드를 게시 할 수 있습니까? –

답변

0

컨테이너 관리 지속성을 사용 중이므로 강제로 트랜잭션을 종료 할 수 없습니다.

무엇을하고 싶은지 em.flush()을 실행하십시오. 또한 EJB 메소드에 트랜잭션 성을 주석으로 추가해야합니다. 따라서 @Requires을 입력하십시오.

+0

그가 거래를 강제로 끝내고있는 라인은 무엇입니까? –

+0

당신은 @required를 의미합니까? 사용되지 않으면 기본적으로 사용됩니다. –

+0

트랜잭션을 강제 종료하는 것이 잘못된 용어 일 수 있습니다. CMP를 사용할 때 트랜잭션을 제어 할 수 없습니다. –

관련 문제