请教?hibernate.cfg.xml 配置问题

juyuquan1986 2010-04-19 02:19:39
请教下

<hibernate-mapping>
<class name="com.song.shopping.entity.User" table="SHOPPING_SONG_USER" schema="OPENLAB">
<id name="userId" type="long">
<column name="USER_ID" precision="22" scale="0" />
<generator class="hilo" />
</id>
<property name="username" type="string">
<column name="USERNAME" length="32" not-null="true" unique="true" />
</property>
<property name="userpwd" type="string">
<column name="USERPWD" length="32" not-null="true" />
</property>
<property name="useremail" type="string">
<column name="USEREMAIL" length="64" not-null="true" />
</property>
<property name="telphone" type="string">
<column name="TELPHONE" length="20" />
</property>
<set name="shoppingSongOrders" inverse="true">
<key>
<column name="USER_ID" precision="22" scale="0" not-null="true" />
</key>
<one-to-many class="com.song.shopping.entity.Order" />
</set>
</class>
</hibernate-mapping>




<id name="userId" type="long">
<column name="USER_ID" precision="22" scale="0" />
<generator class="hilo" />
</id>
上面的配置文件中 主键必须有序列吗?有没有没有序列的时候,没有序列的情况下如何写配置文件?
...全文
165 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
yueweiac110 2010-04-20
  • 打赏
  • 举报
回复
<id name="userId" type="long">
<column name="USER_ID" precision="22" scale="0" />
<generator class="identity" />
</id>
用identity
juyuquan1986 2010-04-19
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 shizao 的回复:]
主键必须要有序列

一般的序列形式是由数字组成的,这个就可以用sequence实现,很方便
但特殊情况下,主键可能由数字+字母,如:5555xxyx,我曾经想实现这种情况的,但没实现....
[/Quote]

郁闷啦,我还想着建联合主键呢,这不更没法配置啦
shizao 2010-04-19
  • 打赏
  • 举报
回复
主键必须要有序列

一般的序列形式是由数字组成的,这个就可以用sequence实现,很方便
但特殊情况下,主键可能由数字+字母,如:5555xxyx,我曾经想实现这种情况的,但没实现....
juyuquan1986 2010-04-19
  • 打赏
  • 举报
回复
现在问题我想知道是
数据库设计时主键列不通过序列生成的,那么在配置文件里要怎么配置?
请教如何配置啊!
zidasine 2010-04-19
  • 打赏
  • 举报
回复
如果不写 可以根据类型自己设置
happyfmy 2010-04-19
  • 打赏
  • 举报
回复
<generator class="assigned"> 程序中自己指定主键
yuling59520 2010-04-19
  • 打赏
  • 举报
回复
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="com.ruining.pojo">
<class
name="DictItem"
table="DICT_ITEM"
>
<id name="dictid" type="string" column="DICTID">
<generator class="sequence">
<param name="sequence">SEQ_DICTITEM</param>
</generator>
</id>

<property
name="groupid"
column="GROUPID"
type="string"
not-null="false"
length="64"
/>
<property
name="dictname"
column="DICTNAME"
type="string"
not-null="false"
length="64"
/>
<property
name="shortname"
column="SHORTNAME"
type="string"
not-null="false"
length="3"
/>
<property
name="updatetime"
column="UPDATETIME"
type="date"
not-null="false"
length="7"
/>


</class>
</hibernate-mapping>
sun1950 2010-04-19
  • 打赏
  • 举报
回复
native 策略是从identity,sequence,hilo中自动选择,这取决于数据库的支持。
hibernate的ID是必须的,identity可以配置标识字段...具体的要自己去找了。。。
yuling59520 2010-04-19
  • 打赏
  • 举报
回复
还是没说明白啊!
juyuquan1986 2010-04-19
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 zqlclj 的回复:]
id name="userId" type="long">
<column name="USER_ID" precision="22" scale="0" />
<generator class="native" />
</id>
[/Quote]

native 就是不使用序列?是这个意思吧?
zqlclj 2010-04-19
  • 打赏
  • 举报
回复
id name="userId" type="long">
<column name="USER_ID" precision="22" scale="0" />
<generator class="native" />
</id>
juyuquan1986 2010-04-19
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 sqd2010 的回复:]
在网上查一下就知道了,网上的资料很多。
[/Quote]

能上网在能在这问吗?呵呵,只能上点技术网站
juyuquan1986 2010-04-19
  • 打赏
  • 举报
回复
呵呵,楼上的各位,理解的和我说的有点不一样啊

有序列的情况下是这样配置,我能理解
但是数据库设计的主键列不是序列生成的,那么在配置文件里要怎么配置?
sqd2010 2010-04-19
  • 打赏
  • 举报
回复
在网上查一下就知道了,网上的资料很多。
风起于默 2010-04-19
  • 打赏
  • 举报
回复
这个都是根据你的数据库生成的
newplayerone 2010-04-19
  • 打赏
  • 举报
回复
<generator class="hilo" />这个意味着 你的主建是由 hilo这个类创建的,所以在装载数据的时候调用这个类来产生主建。

不过估计楼主的本意不是这样的。
如果想自增 ,oracle里面有sequence来实现

<generator class="sequence">
<param name="sequence">自己创建的sequence</param>
</generator>
这样就不需要你去关心主建,程序会自己从sequence里面去取得
生活 2010-04-19
  • 打赏
  • 举报
回复
顶下,回复内容太短了!

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧