就是我之前数据库已经有很多表了,我现在新写了个实体类,和..hbm.xml文件,现在想把这个表映射到数据库,就是在数据库创建出这个表,怎么整?不能数据库表都删了然后都重新创建,是创建一个新表不影响数据库中的原有表
解决方案 »
- JAVA控制针式打印机的问题
- 有人会配jprofiler6吗
- 在tomcat中使用数据库连接池的问题
- 请教,关于jquery里给新建的标签加click事件的问题
- 求svfrClient.jar
- 关于对SSH项目进行Junit单元测试的问题
- 为什么我的Spring+Hibernate+Struts使用JNDI后,第一次保存成功,第二次保存不成功?
- 关于weblogic 9.0与spring 2.0的问题
- 关于struts验证框架的问题?
- 新手提问~~为什么Date对象的getTime总返回一个值啊?
- 一个java导出数据的小问题,希望高手解决!
- 在SPRING2.5与HIBERNATE3.0结合的项目中 spring是怎么管理session的?
如果有了,他不会帮你建了..
package cn.wang.usermanager.entities;import java.io.Serializable;public class User implements Serializable { private static final long serialVersionUID = 710652653888362545L; private Integer id;
private String name;
private String password;
private String sex;
private String address;
private String email; public User() {}
public Integer getId() {
return id;
} public void setId(Integer id) {
this.id = id;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} public String getSex() {
return sex;
} public void setSex(String sex) {
this.sex = sex;
} public String getAddress() {
return address;
} public void setAddress(String address) {
this.address = address;
} public String getEmail() {
return email;
} public void setEmail(String email) {
this.email = email;
}
}
对应的映射文件:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping package="cn.wang.usermanager.entities">
<class name="User" table="t_user">
<id name="id">
<generator class="native"/>
</id>
<property name="name" not-null="true" length="15" />
<property name="password" not-null="true" length="15"/>
<property name="sex" />
<property name="address" />
<property name="email"/>
</class>
</hibernate-mapping><!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration>
<session-factory>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/ssh</property>
<property name="connection.username">root</property>
<property name="connection.password">LIUWANG521</property>
<property name="hbm2ddl.auto">update</property>
<property name="connection.autocommit">true</property>
<mapping resource="cn/wang/usermanager/entities/User.hbm.xml"/>
<!--
<class-cache
class="org.hibernate.test.legacy.Simple"
region="Simple"
usage="read-write"/>
-->
</session-factory>
</hibernate-configuration>
spring配置文件
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <!-- 配置sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml" />
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!--配置事务的传播特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
<!--那些类的哪些方法参与事务 -->
<aop:config proxy-target-class="true">
<aop:pointcut expression="execution(* cn.wang.usermanager.managers.managerimpl*.*(..))" id="allManagerMethod"/>
<aop:advisor pointcut-ref="allManagerMethod" advice-ref="txAdvice" />
</aop:config>
<bean id="userManager" class="cn.wang.usermanager.managers.impls.UserMangerImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean name="/user" class="cn.wang.usermanager.actions.UserAction">
<property name="userManager" ref="userManager"/>
</bean>
</beans>