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......
|