Hi,
I have a problem when 'persist' a new entity and 'update' his childs
(OneToMany).
It seems like first entity don't refresh!!!
These are my 2 entities with a OneToMany and ManyToOne relation:
----------------------------------------------------
Entity
@Table(name = "cards")
public class Card implements Serializable
{
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE)
@Column(name="id_card")
private int idCard;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "card", cascade =
CascadeType.ALL)
@JoinColumn(name = "id_card")
List<Transaction> transactions;
...
}
@Entity
@Table(name = "transactions")
public class Transaction
{
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE)
@Column(name = "id_transaction")
private int idTransaction;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "id_card")
private Card card;
....
}
----------------------------------------------------
And this is my code:
----------------------------------------------------
....
em.getTransaction().begin();
Card card = new Card();
....
card.setName('fff');
....
....
em.persist(card);
....
....
Colection<Transaction> transactions = .....
for (Transaction transaction : transactions )
{
transaction.setCard(card);
em.update(transaction);
}
int num_transactions = card.getTransactions().size();
em.getTransaction().commit();
System.out.println("Num Transactions:"+num_transactions); <---------------
SHOW ME ZERO RESULTS!!!!
----------------------------------------------------
Last line show me 0 results!!!! Why????????
Thanks in advance,
--
View this message in context: http://www.nabble.com/Problem-with-OneToMany-tp16827031p16827031.html
Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.