首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

100分求大家帮忙看一下,关于Hibernate 注解自动生成表有关问题

2012-01-26 
100分求大家帮忙看一下,关于Hibernate 注解自动生成表问题用hibernate自动生成表不成功。找了半天,不知道是

100分求大家帮忙看一下,关于Hibernate 注解自动生成表问题
用hibernate自动生成表不成功。找了半天,不知道是什么问题,望大家帮我看看,谢谢了。
web.xml 代码
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>gwbnsq</display-name>
<!--Spring的ApplicationContext 载入 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Spring 刷新Introspector防止内存泄露 -->
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>
  <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>


applicationContext.xml[color=#FF0000][/color]
<?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:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-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/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
default-lazy-init="true">
<description>Spring公共配置 </description>
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list><value>/WEB-INF/classes/application.properties</value></list>
</property>
</bean>
<!-- 数据源配置,使用应用内的DBCP数据库连接池 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<!-- Connection Info -->
<property name="driverClassName" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<!-- Connection Pooling Info -->
<property name="initialSize" value="5" />
<property name="maxActive" value="100" />
<property name="maxIdle" value="30" />
<property name="maxWait" value="500" />
<property name="poolPreparedStatements" value="false" />
<property name="defaultAutoCommit" value="false" />
</bean>
<!-- Hibernate配置 -->
<bean id="sessionFactory"


class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="namingStrategy">
<bean class="org.hibernate.cfg.ImprovedNamingStrategy" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">create</prop>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
</props>
</property>
<property name="packagesToScan" value="com.gwbnsq.entity.*"/>
</bean>
</beans>


UserInfo.java
package com.gwbnsq.entity;


import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

@Entity
@Table(name = "TB_USERINFO")
public class UserInfo {

private String username;
private String password;

@Column(nullable = false,length =20)
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}

@Column(nullable = false,length =20)
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}

}

[color=#00FF00]各位,我试过修改,<property name="packagesToScan" value="com.gwbnsq.entity.*"/>改为,com.gwbnsq.entity,或者改为。com.gwbnsq.entity都没有效果,[/color]

谢谢各位大哥大姐了。帮帮忙看看。



[解决办法]
注解生成
还没弄过
楼主是个小mm
[解决办法]
在配置文件中 加一行<property name="hibernate.hbm2ddl.auto">true</property> 就OK 了
[解决办法]
在运行应用程序时(第一次),会自动建立起表的结构(前提是先建立好数据库)。要注意的是,
当部署到服务器后,表结构是不会被马上建立起来的,是要等应用第一次运行起来后才会 。

我刚自己试了下,发现能自己建立表的。
[解决办法]
没看到你的hibernate映射文件。
那个
<property name="mappingResources">
<list>
<value>表对应的xml</value>
</list>
</property>
这个在哪?
[解决办法]
我没做过自动生产表!
干嘛不自己建表呢/
根据表来自动生成映射配置一般是不会发生错误的!

热点排行