Witam,
Mam problem ponieważ chce zapisać firmę z formatki
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>My JSF Page</title>
</h:head>
<h:body>
<h:form id="list">
<p:panel header="#{comRes.adding_company}">
<p:panelGrid columns="4" style="border:0">
<h:outputLabel for="id" value="Id" />
<p:inputText id="id" disabled="true" label="Id"
value="#{companyHome.selectedCompany.id}" />
<h:outputLabel for="address" value="#{comRes.address}" />
<p:inputText id="address" required="true" label="#{comRes.address}" value="#{companyHome.selectedCompany.address}" />
<h:outputLabel value="#{comRes.city}" />
<p:inputText id="city" required="true" label="#{comRes.post_code}" value="#{companyHome.selectedCompany.city}" />
<h:outputLabel value="#{comRes.post_code}" />
<p:inputText id="postCode" required="true" label="#{comRes.post_code}" value="#{companyHome.selectedCompany.postCode}" />
<h:outputLabel value="#{comRes.phone}" />
<p:inputText id="phone" required="true" label="#{comRes.phone}" value="#{companyHome.selectedCompany.phone}" />
<h:outputLabel value="#{comRes.mail}" />
<p:inputText id="mail" required="true" label="#{comRes.mail}" value="#{companyHome.selectedCompany.mail}" />
<h:outputLabel value="#{comRes.nip}" />
<p:inputText id="nip" required="true" label="#{comRes.nip}" value="#{companyHome.selectedCompany.nip}" />
</p:panelGrid>
<p:commandButton ajax="true" value="#{menRes.save}" action="#{companyHome.saveAction}"/>
</p:panel>
</h:form>
</h:body>
</html>
Po uzupełnieniu klikam w przycisk zapisz
package pl.luppo.view;
import javax.ejb.Stateful;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
import pl.luppo.ztz.model.Company;
@Stateful
@ManagedBean
@SessionScoped
public class CompanyHome{
@PersistenceContext(unitName="industry", type=PersistenceContextType.TRANSACTION)
EntityManager entityManager;
private Company selectedCompany;
public String addAction(){
selectedCompany = new Company();
return "/view/company/companyEdit.xhtml";
}
public String saveAction(){
System.out.println(selectedCompany.toString());
entityManager.merge(selectedCompany);
return "/view/company/companyView.xhtml";
}
public Company getSelectedCompany() {
return selectedCompany;
}
public void setSelectedCompany(Company selectedCompany) {
this.selectedCompany = selectedCompany;
}
}
Otrzymuje komunikat
javax.persistence.TransactionRequiredException: JBAS011469: Transaction is required to perform this operation (either use a transaction or extended persistence context): javax.faces.FacesException: #{companyHome.saveAction}: javax.persistence.TransactionRequiredException: JBAS011469: Transaction is required to perform this operation (either use a transaction or extended persistence context)
moj plik persistence.xml wyglada
<?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="industry" transaction-type="JTA">
<jta-data-source>java:/ztz</jta-data-source>
<properties>
<!-- property name="packagesToScan" value="br.com.template.entity" /-->
<property name="hibernate.archive.autodetection" value="class, hbm" />
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.show_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>
Jeśli ktoś wie dlaczego podczas zapisu występuje błąd transakcji to prosiłbym o pomoc
Z góry dziękuję