[EJB 3.0] - Detached entity passed to persist
by jactor
Hi!
I receive an error when I try to persist an entity bean. I have a bean (A) which relates to another bean (B). This relation is annotated as @ManyToOne(cascade = CascadeType.ALL) and
@JoinColumn(nullable = false)
The enity bean (B) has only one property beside the autogenerated id (Long) which its name (b.getName()). This property is annotated with @Column(nullable = false, unique = true).
I use annotations over the fields of the properties.
When I persist/merge these entities I get
javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: a.package.B
|
The methods which tries to persist the entities are:
| public Long saveOrUpdate(A a) {
| B b = a.getB();
| b.setId(saveOrUpdate(b));
| entityManager.flush();
|
| // If b is persisted before, the persisting gives an exception
| // I have actually never tried the merge option as a.getId() is null...
|
| if (a.getId() != null) {
| entityManager.merge(a);
|
| return a.getId();
| }
|
| entityManager.persist(a);
|
| return a.getId();
| }
|
| public Long saveOrUpdate(B b) {
| B persistedB = get(b.getName());
|
| if (persistedB != null) {
| return persistedB.getId();
| }
|
| entityManager.persist(b);
|
| return b.getId();
| }
|
Since B only have one property (name) and this is unique, my saveOrUpdate method of B only return the id of an allready saved instance. Therefore I use this id on B.setId(Long id) when the method is called.
If B has not been persisted before it works as intended, but if the instance of B is located in the database, then the exception is thrown when I try to persist A... When A is persisted (even though there is a merge option in the code, every time I use this code, I persist a new instance of A - a.getId() == null - which may have an allready persisted instance of B) this exception is thrown even if the correct id is located in the instance of B which is tried to be persisted with A.
Please help me with this exception. I thought a detached entity did not have a valid primary key (b.getId()), but this is not the case in this situation. I am growing frustrated...
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3972588#3972588
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3972588
19 years, 7 months
[JBoss jBPM] - Adding Implementation to BPEL Orchestration
by KVAK_TNT
Hi there!
I have a small question about the ATM example in the BPEL-Extension.
(Its a little bit more general, but I want to use the ANT-Scripts of this example in my project)
OK - If I add some functionality in the _impl - Files of the atm example directly it will be overwritten if I start a build.
If I add some functionality in the _impl - Files of Partners like ticket - it won't be overwritten on a build.
Why?
Also: If I add some functions in the wsdl-Files of the ATM (frontend.wsdl) - this new functions will be implemented in the xxservice.java
If I add the same stuff in e.g. the ticket.wsdl - nothing happens in my partner ....java files.
Whats the reason?
Where is the "switch" where I can change sucha behavior?
Greetings
Claus
Student (BA)
eMundo GmbH - Germany
I'm working on a BPEL Processintegration Framework to achieve my Bachelor grade.
For more information see Agilpro
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3972586#3972586
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3972586
19 years, 7 months
[JBoss Seam] - Problem to submit a form with commandButton
by bagrehc
Hi all,
I'm new using JSF and i'm trying to create a application like the DVDStore example.
I have a form that represents an EntityBean "atdo" and a SLSB called "atdoAction" that persist this "atdo".
Well, my problem is that when a click on the button of my xhtml page to call the "atdoAction.save" method the application simply return to the same page without call the method. But when I set "immediate" parameter of commandButton to "true", then the application call the method, but the informations supplied on form isn't attributed to de "atdo" object.
My test.xhtml page:
------
#some code before
<h:form >
| <h:inputHidden value="#{atdo.codigo}" />
| <h:panelGrid columns="2" >
| <h:outputText value="Codigo Cliente:"/>
| <h:inputText value="#{atdo.codigoCliente}" title="CodigoCliente" />
| <h:outputText value="Solicitante:"/>
| <h:inputText value="#{atdo.solicitante}" title="Solicitante" />
| <h:outputText value="Obs:"/>
| <h:inputTextarea value="#{atdo.obs}" title="Obs" />
| </h:panelGrid>
| <h:commandButton type="submit" action="#{atdoAction.save}" value="Criar Atendimento"/>
| </h:form>
|
#some code after
-------
My atdoAction:
----------------------
@TransactionManagement(TransactionManagementType.BEAN)
| @Stateless
| @Name("atdoAction")
| public class AtendimentoBean implements AtendimentoLocal, AtendimentoRemote {
|
| @PersistenceContext(unitName="atendimento")
| EntityManager em;
|
| @Resource
| UserTransaction utx;
|
| @In
| AtendimentoEntity atdo;
|
| public String save() throws Exception {
| try {
| utx.begin();
|
| em.persist(atdo);
| utx.commit();
|
| } catch (Exception e) {
| utx.rollback();
|
| e.printStackTrace();
| throw new Exception(e.getMessage());
| }
|
| return "success";
| }
| }
| -----------------------------------
My "atdo"
-----------------------------------
@Name("atdo")
| @Scope(ScopeType.SESSION)
| @SequenceGenerator(name = "atendimento_seq", sequenceName = "atendimento_codigo_seq", allocationSize=1)
| @Entity
| @Table(name = "atendimento", uniqueConstraints = {
| @UniqueConstraint(columnNames = { "protocolo" }) })
| public class AtendimentoEntity implements Atendimento{
|
| private Integer codigo;
|
| private String obs;
|
| private String solicitante;
|
| private String codigoCliente;
|
| @Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="atendimento_seq")
| @Column(name = "codigo", unique = true, nullable = false, insertable = true, updatable = true)
| public Integer getCodigo() {
| return codigo;
| }
|
| public void setCodigo(Integer codigo) {
| this.codigo = codigo;
| }
|
| @Column(name = "cliente", unique = false, nullable = false, insertable = true, updatable = true, length=10)
| public String getCodigoCliente() {
| return codigoCliente;
| }
|
| public void setCodigoCliente(String codigoCliente) {
| this.codigoCliente = codigoCliente;
| }
|
|
| @Lob
| @Column(name = "obs", unique = false, nullable = false, insertable = true, updatable = true)
| public String getObs() {
| return obs;
| }
|
| public void setObs(String obs) {
| this.obs = obs;
| }
|
|
| @Column(name = "solicitante", unique = false, nullable = false, insertable = true, updatable = true, length=50)
| public String getSolicitante() {
| return solicitante;
| }
|
| public void setSolicitante(String solicitante) {
| this.solicitante = solicitante;
| }
|
| }
| -----------------------------------
So, if someone could help me, I'd be very thanked.
Reginaldo L. Russinholi
System Analyst / Developer
Sun Certified Java Programmer
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3972585#3972585
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3972585
19 years, 7 months
[JBoss Seam] - Re: Glaring Security Hole?
by bfagan
I don't think it's any more of a hassle than creating a @Remote or @WebSerivce interface. In fact we're talking about just one tag, @WebRemote, in a class.
It would also be easier for developers who are new to Seam Remoting to follow if it is consistent. "I have to use @WebRemote on sessions, but @NoWebRemote on entities? Why'd that do that?"
If you're worried about existing developers or eliminating the speed-bump, you can always create a property in a config file somewhere that would enable/disable entity model remoting restrictions.
>From a security standpoint, I think it's much better to err on the side of security, i.e. you have to specifically enable which entity models you want exposed.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3972579#3972579
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3972579
19 years, 7 months