-->
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: trouble inserting by query on entity with embedded object
PostPosted: Tue Jul 01, 2008 4:08 pm 
Newbie

Joined: Tue Jan 11, 2005 2:26 pm
Posts: 15
Hi,

How do you insert multiple rows using Hibernate's Insert Select statement?

My Project is using EJB3 and Hibernate's EntityManager.

My Entity has an Embedded AuditEntry object that is giving me problems.

I've tried various approaches but can't get it to work. Thanks for any help in advance.

Hibernate version:
3.2.0.ga

Mapping documents:

@MappedSuperclass
@AccessType("field")
abstract public class ImmutableEntity extends BaseEntity {

@Embedded
private AuditEntry auditEntry;
// AuditEntry is a (DateTime createdDate, Long createdByOperatorId) object
// get/set AuditEntry methods
}

public class VenueConfigurationSeat extends ImmutableEntity {

// other fields

}

Here's what I'm trying to do

String SQL =
"INSERT INTO VenueConfigurationSeat (a, b, c, auditEntry) " +
"SELECT a, b, c, :auditEntry " +
"FROM a, b, c" +
"WHERE ...";

Long operatorId = // get operatorId
DateTime createdDate = new DateTime();
AuditEntry auditEntry = new AuditEntry(createdDate, operatorId);

// execute Query
getEntityManager().createQuery(SQL)
.setParameter("venueConfigId", venueConfiguration.getId())
.setParameter("auditEntry", auditEntry)
.executeUpdate();

I've also tried a few other approaches from nested paths (auditEntry.createdDate, auditEntry.createdByOperatorId) to selecting new objects (select new com.mydomain.AuditEntry(:createdDate, :createdbyOperatorId).

No approach has had any success and each approach has thrown various exceptions from IllegalArgumentException to bad syntax to property unresolvable exceptions.

Here's some of the other approaches that I've also tried

Alt approach 1 - nested path:

INSERT INTO VenueConfigurationSeat(a, b, c, auditEntry.createdDated, auditEntry.createdByOperatorId)
SELECT a, b, c, :createdDate, :createdByOperatorId

Alt approach 2 - add setCreatedDate and setCreatedByOperatorId method on VenueConfigurationSeat

- Hibernate Exception - could not resolve property: createdDate of: com.tickets.domain.venue.entity.VenueConfigurationSeat

Alt approach 3 - add constructor to AuditEntry(DateTime createdDate, Long createdByOperatorId) - also added default public constructor

INSERT INTO VenueConfigurationSeat(a, b, c, auditEntry)
SELECT ... new com.mydomain.AuditEntry(:createdDate, :createdByOperatorId) ....


Thanks!
-Ben


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.