原创作者: gigix   阅读:1313次   评论:0条   更新时间:2011-05-26    
http://www.almaer.com/blog/archives/000993.html
引用
I am getting to play with Hibernate 3, and they have done a nice job. I was poking around the Caveat Emptor example from Hibernate in Action, which was updated for Hibernate3.

I happened across this file: package-info.java:

@TypeDefs({
	@TypeDef(
		name="monetary_amount_usd",
		typeClass = MonetaryAmountType.class,
		parameters = { @Parameter(name="convertTo", value="USD"); }
	);,
	@TypeDef(
		name="monetary_amount_eur",
		typeClass = MonetaryAmountType.class,
		parameters = { @Parameter(name="convertTo", value="EUR"); }
	);,
	@TypeDef(
		name="item_state",
		typeClass = EnumUserType.class,
		parameters = { @Parameter(name="enumClassName", value="org.hibernate.ce.auction.model.ItemState"); }
	);,

    @TypeDef(
        name="creditcard_type",
        typeClass = EnumUserType.class,
        parameters = { @Parameter(name="enumClassName", value="org.hibernate.ce.auction.model.CreditCardType"); }
    );,
    @TypeDef(
        name="rating",
        typeClass = EnumUserType.class,
        parameters = { @Parameter(name="enumClassName", value="org.hibernate.ce.auction.model.Rating"); }
    );
});

@NamedQueries({
    @NamedQuery(
        name="minBid",
        queryString="select b from Bid b where b.amount.value = (select min(b.amount.value); from Bid b where b.item.id = :itemid);"
    );,
    @NamedQuery(
        name="maxBid",
        queryString="select b from Bid b where b.amount.value = (select max(b.amount.value); from Bid b where b.item.id = :itemid);"
    );
});

package org.hibernate.ce.auction.persistence;

import org.hibernate.annotations.*;
import javax.persistence.*;


Is this better than XML? To have this code sucked in?

NOTE: You don't have to use the annotations of course.
评论 共 0 条 请登录后发表评论

发表评论

您还没有登录,请您登录后再发表评论

文章信息

Global site tag (gtag.js) - Google Analytics