我有三个实体,其中我尝试只保存1个实体。所有三个实体如下: -对象需要时间才能保持休眠
1.学生实体
<class name="com.school.Student" table="TABLE_STUDENT">
<id name="id" type="long">
<column name="ST_ID" />
<generator class="native" />
</id>
<property name="name" type="string" column="ST_NAME"/>
<many-to-one name="studentSection" class="com.school.Section" fetch="select">
<column name="SECTION_ID" not-null="true" />
</many-to-one>
<many-to-one name="studentSportsTeam" class="com.school.SportsTeam" fetch="select">
<column name="SPORTS_TEAM" not-null="true" />
</many-to-one>
</class>
2.第实体
<class name="com.school.Section" table="TABLE_SECTION">
<id name="sectionId" type="string">
<column name="SECTION_ID" />
<generator class="assigned" />
</id>
<property name="floor" type="string" column="SEC_FLOOR"/>
<property name="capcacity" type="int" column="SEC_CAPACITY"/>
<set name="studentDetails" inverse="true" lazy="true" table="TABLE_STUDENT" fetch="select">
<key>
<column name="SECTION_ID" not-null="true" />
</key>
<one-to-many class="com.school.Student" />
</set>
</class>
3 SprotsTeam实体: -
<class name="com.school.SportsTeam" table="TABLE_SPORTS">
<id name="sportsTeamId" type="string">
<column name="SPORTS_TEAM" />
<generator class="assigned" />
</id>
<property name="noOfPlayers" type="int" column="SPORTS_PLAYER_NUM"/>
<property name="captainName" type="string" column="SPORTS_CAPTAIN_NAME"/>
<set name="playerDetails" inverse="true" lazy="true" table="TABLE_STUDENT" fetch="select">
<key>
<column name="SPORTS_TEAM" not-null="true" />
</key>
<one-to-many class="com.school.Student" />
</set>
</class>
现在,如果我尝试使用正确的Section
和SportsTeam
详细信息保存Student
实体,则需要很长时间才能将其保存到数据库中。目前我正在为大约10000名学生运行它,而这个过程(只有持续)大约需要15分钟。我添加了一些记录器来计算完整时间。
现在我需要缩短这段时间,因为我们将从1万条缩短到100万条记录,并且按照计算它需要很长时间..我需要缩短时间,我该怎么做?
根据需要,也是模式是如下: -
表学生:
ST_ID NUMBER,
ST_NAME VARCHAR(40),
SECTION_ID VARCHAR(10),
SPORTS_TEAM VARCHAR(10)
TABLE_SECTION:
SECTION_ID VARCHAR(10),
SEC_FLOOR VARCHAR(2),
SEC_CAPACITY NUMBER
TABLE_SPORTS:
SPORTS_TEAM VARCHAR(10),
SPORTS_PLAYER_NUM NUMBER,
SPORTS_CAPTAIN_NAME VARCHAR(40)
请帮
您是否使用hibernate工具生成数据库模式? – 2011-06-09 05:28:22
我用hbm2ddl属性一次生成模式,之后我以更新模式运行代码。 – 2011-06-09 05:30:17
请显示用于将实体插入数据库的代码 – bbaja42 2011-06-09 05:43:55