Hi.
I write a simple web application.
I use Seam Framework with Hibernate libs.
i have a problem, a cant save injected values...
here are some code:
my stateful bean
Code:
@Name("myStatefulBean")
@Stateful
@Interceptors(SeamInterceptor.class)
@Scope(ScopeType.SESSION)
public class stSB implements stSBRemote, stSBLocal {
@PersistenceContext
private Session sessionH;
@In(create=true) @Out
private cartElement cartEl;
private List<Long> cart;
public stSB() {
cart = new ArrayList<Long>();
}
public void addItem()
{
try
{
sessionH.beginTransaction();
sessionH.save(cartEl);
sessionH.getTransaction().commit();
}
catch (HibernateException e) {
sessionH.getTransaction().commit();
System.out.println("saveItem exception");
}
}
// getters - setters, @destroy @remove methods, other methods
}
my entity
Code:
@Entity
@Table(name="CARTELEMENTS")
@Name("cartEl")
public class cartElement implements Serializable{
private Double price;
private String name;
private Date date;
private Long pid;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
public cartElement(){
}
public cartElement(Double price, String name, Date date){
this.price = price;
this.name = name;
this.date = date;
}
@PostConstruct
public void init()
{
System.out.println("cartElement INIT()");
}
//getters setters
}
and part of web form
Code:
.....
<h:panelGrid columns="2" rowClasses="prop" columnClasses="name,value">
<h:outputLabel for="name">Name</h:outputLabel>
<h:inputText id="name" value="#{cartEl.name}"/>
<h:outputLabel for="date">Date</h:outputLabel>
<rich:calendar value="#{cartEl.date}"/>
<h:outputLabel for="pid">PID</h:outputLabel>
<h:inputText id="pid" value="#{cartEl.pid}">
<f:validator validatorId="pidValidator"/>
<f:converter converterId="strToLongConverter"/>
</h:inputText>
<h:outputLabel for="price">Price</h:outputLabel>
<h:inputText id="price" value="#{cartEl.price}">
<f:converter converterId="strToDoubleConverter"/>
</h:inputText>
</h:panelGrid>
<h:commandButton id="submit" value="Add record" action="#{myStatefulBean.addItem()}"/>
Lets i describe a problem.
After clicking button
<h:commandButton id="submit" value="Add record" action="#{myStatefulBean.addItem()}"/>
values are injected into
Code:
@In(create=true) @Out
private cartElement cartEl;
but, when runtime tries to execute code sessionH.save(cartEl); , it throws exception -
Unknown entity: org.domain.seamtest.stateful.cartElement_$$_javassist_seam_3
and values of cartEl are NULL, but proxy JavaBeanInterceptor includes real values.
But if i create a local varriable and copy there field values from injected object (using cartEl.getXXX() methods) - sessionH.save(..) saves object with out any exception, but it is not what i want :(
So, how to solve my problem - how i can persist (save) my @in cartEl object?