开发者

collection-type argument in Hibernate?

开发者 https://www.devze.com 2023-01-16 23:05 出处:网络
I was thinking if I could set the list elements type in hibernate mapping files. So far I found this collection-type attribute like here:

I was thinking if I could set the list elements type in hibernate mapping files.

So far I found this collection-type attribute like here:

<list name="privileges" cascade="all" table="user_privilege" collection-type="">

, but I am not sure if I put my list element full class name if Hibernate will generate my domain classes properly.

Is there another way of doing this or I have to manually set types of my Lists in my classes like here:

Generated by Hibernate:

private List privileges = new ArrayList(0);

Manually changed:

private List<UserPrivilege> privileges = new ArrayLi开发者_运维百科st(0);

Thanks.


collection-type attribute set's type of collection class if you want to use some custom Collection implementation, other then standard java.util.ArrayList et consortes.

If your mappings are correct it's just a matter of hbm2java tool settings. See reference.

Example:

<hibernatetool destdir="${build.dir}/generated">
  <configuration configurationfile="hibernate.cfg.xml"/>
  <hbm2java jdk5="true"/>
</hibernatetool>
0

精彩评论

暂无评论...
验证码 换一张
取 消