|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Member
Iscritto dal: Jul 2011
Messaggi: 152
|
ejb 3.0 dubbi sull utilizzo
Allora per l'uni devo fare uno stage dove devo imparare java server faces e ejb 3.0..Il primo l'ho imparato,ho qualche difficoltà con ejb 3.0 sto leggendo un libro e mi sono bloccato qui:
@Entity public class Employee { @Id private int id; private String name; private long salary; public Employee() {} public Employee(int id) { this.id = id; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public long getSalary() { return salary; } public void setSalary (long salary) { this.salary = salary; } } Persisting an entity is the operation of taking a transient entity, or one that does not yet have any persistent representation in the database, and storing its state so that it can be retrieved later. This is really the basis of persistence—creating state that may outlive the process that created it. We are going to start by using the entity manager to persist an instance of Employee. Here is a code example that does just that: Employee emp = new Employee(158); em.persist(emp); The first line in this code segment is simply creating an Employee instance that we want to persist. If we ignore the sad fact that we seem to be employing a nameless individual and paying them nothing (we are setting only the id, not the name or salary) the instantiated Employee is just a regular Java object.a regular Java object. The next line obtains an entity manager and uses it to persist the entity. Calling persist() is all that is required to initiate it being persisted in the database. If the entity manager encounters a problem doing this, then it will throw an unchecked PersistenceException; otherwise the employee will be stored in the database. When the persist() call returns, emp will be a managed entity within the entity manager’s persistence context Io:: Non ho capito ma devo implementare io la funzione persist e creare l'entity manager ,inoltre introdurre un campo entity manager nella classe o viene fatto in automatico????Perchè da come descrive il libro sembra che tutto venga fatto in automatico? Ultima modifica di gaiapuffo : 01-10-2013 alle 10:18. |
|
|
|
|
|
#2 |
|
Member
Iscritto dal: Jul 2011
Messaggi: 152
|
risolto
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 13:52.



















