-->
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.  [ 2 posts ] 
Author Message
 Post subject: Help instantiating embedded objects with annotations.
PostPosted: Thu Feb 12, 2009 10:00 pm 
Newbie

Joined: Wed Feb 11, 2009 7:09 pm
Posts: 1
Location: Colorado USA
Hello,

Hibernate version:3.3.1
Annotations version: 3.4.0
MySql 5.1.11

It's not clear to me how to set up annotations for embedded objects. At this point, I'm just looking at the retrieval side.

Guess I'd like to know how to retrieve stuff from the db via stored procedures and instantiate various embedded objects in the application. No problem calling stored procs....I'm using native queries. No problem with primitive data type mappings. Big problems trying to map db columns to custom object types.

Specifically, how can I retrieve columns from the db defined as DECIMAL(6,2) and map them to an embedded custom object in the application called Money? The relationship is always one-to-one.

I've tried lots of things, lastly being the use of dot notation in the ResultSetMapping for the embedded object. Seems like the documentation regarding annotations for embedded objects is pretty thin....it's confusing to me, anyway.

The code below is crap, I admit. And is not useful except or the class definitions.

Is there somewhere, a good example that shows the correct approach for instantiating embedded objects from a native query call?

Class Money {
@Id @Column(name="moneyId")
private int id;
@Column(name="anAmount")
private BigDecimal anAmount;
private String currency;
...........
}

Class Quote {
@Id @Column(name="quoteId")
private int quoteId;
private Date quoteDate;
private Money depositAmount;
private float percentSalesTax;
.............
}

I have NativeQueries and SQLMappings like this:

@SqlResultSetMapping(name = "getAQuoteMap", entities = {
@EntityResult(entityClass = Quote.class, fields = {
@FieldResult(name = "quoteId", column = "quoteID"),
@FieldResult(name = "quoteDate", column = "quoteDate"),
@FieldResult(name = "depositAmount.anAmount", column = "depositAmt"),
@FieldResult(name = "depositAmount.moneyId", column = "depositAmtId"),
@FieldResult(name = "percentSalesTax", column = "percentSalesTax"),
etc..................
@SqlNativeQuery(name = "getAQuote",
query = "call getAQuote(:qid)",
callable = true,
resultSetMapping = "getAQuoteMap" )

SPROC: getAQuote(INT rid) select quoteID,quoteDate,depositAmt,depositAmtId,percentSalesTax......


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2009 10:44 pm 
Senior
Senior

Joined: Tue Aug 01, 2006 9:24 pm
Posts: 120
I am not sure if this is what your looking for but did you try using the select clause like this

Code:
SELECT new org.yourpackage.Money(dbvalue)


of course you'll need a constructor that can take the returned object on your money class.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

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.