openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From infinity2heaven <infinity2hea...@gmail.com>
Subject Update statements not generated for a @OneToMany mapping
Date Tue, 14 Jun 2011 22:18:09 GMT
OpenJPA 1.2.2
Spring 3
HSQLDB 2.0
JUnit Testing with SpringJUnit4ClassRunner & Spring @Transactional on
Testclass
--

class Settlement {

	@OneToMany(mappedBy = "settlement", Cascade=CascadeType.REFRESH)
	private List<VoucherProcessed> vouchersProcessed = new
ArrayList<VoucherProcessed>(0);
   
    ...
}

public class VoucherProcessed {

	@OneToOne
	@JoinColumn
	private Voucher voucher;

	@ManyToOne
	@JoinColumn
	private Settlement settlement;

    ...

}

The service class passes a new Settlement object along with a list of
vocherIds (since VoucherProcessed
are already persisted)

// dao
@Transactional
public void save(Settlement settlement, List<Long> voucherIds) {
    // Load VoucherProcessed
	List<VoucherProcessed> vouchersProcessed = (List<VoucherProcessed>) em
		.createQuery("SELECT vp FROM VoucherProcessed vp WHERE
vp.voucher.voucherId IN (:voucherIds)")
			.setParameter("voucherIds", voucherIds).getResultList();

	if (vouchersProcessed != null) {
		settlement.setVouchersProcessed(vouchersProcessed);
		em.persist(settlement);
	}
}


The above code generates INSERT for settlement but there's no update for
Voucher like:
UPDATE Voucher SET settlement.id=?

However, if I pass Settlement with a persistent VoucherList to the dao,
Update is generated. 

What am I missing?

--
View this message in context: http://openjpa.208410.n2.nabble.com/Update-statements-not-generated-for-a-OneToMany-mapping-tp6476296p6476296.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Mime
View raw message