-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: DETACHED ENTITY EXCEPTION IN JPA
PostPosted: Sun Jan 17, 2010 7:59 am 
Newbie

Joined: Tue Nov 03, 2009 9:59 am
Posts: 5
Hi All,

Pls I have being bugged down by the detached entity exception I have tried lots of things all to no avail
below is an extract from my entity class .

package com.taysay.drivetru.entity;

import static org.jboss.seam.ScopeType.SESSION;

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;
import javax.persistence.TableGenerator;

import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;



@Entity
@Name("demo")
@Scope(SESSION)
@Table(name="DEMO")
public class Demo implements Serializable {


private int id;
private String name;


@TableGenerator(name="demo_Gen",
table="ID_GEN",
pkColumnName="GEN_NAME",
valueColumnName="GEN_VAL",
pkColumnValue="demoid_Gen",
initialValue=10000,
allocationSize=100)
@Id @GeneratedValue(strategy=GenerationType.TABLE,generator="demo_Gen")
@Column(name="DEMO_ID")
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Column(name="NAME")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}


}


// Action class

package com.taysay.drivetru.actions;

import javax.ejb.Remove;
import javax.ejb.Stateful;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.jboss.seam.annotations.Destroy;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;

import com.taysay.drivetru.entity.Demo;


//@Stateless
@Stateful
@Name("demoManager")
public class DemoActionBean implements DemoManager{

// @PersistenceContext
@PersistenceContext (type=PersistenceContextType.EXTENDED)
private EntityManager em;

@In (required=false) @Out (required=false)
private Demo demo;

public void save()
{
System.out.println(": THE SAVE DEMO :"+demo.getId());


em.persist(demo);


}


@Destroy @Remove
public void destroy() { }


}

// Interface

package com.taysay.drivetru.actions;

public interface DemoManager {

public void save();

public void destroy();

}


now I came don to this simple class when I had issues in some other class so wrote a simple class with the aim of
having a more manageable situation.

initially I had my EntityManager em; annotated with the // @PersistenceContext

but when the exception was thrown i did this (the EXTENDED clause)
@PersistenceContext (type=PersistenceContextType.EXTENDED)

Yet this ugly exception wont let me be , I am working from eclipse ganymede Version: 3.4.2


Pls can some one tell me what exactly i am doing wrong, what happen is that I am generating my Id from a table
now at the first instance of application start off I get to make a successfull insertion to the back end (MYSQL 5) but subsequent attempts lead to this ugly guy throwing exceptions at me. prior to a successful insertion the ID is 0 but subsequently it carries the values of the just persisted id .

Pls I urgently need help, Asap


Thanks in earnest for your invaluable help. Thank you Have a wonderful day.


Have a bug free week .

Taysay


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.