hibernate映射文件无法使用length指定int和Integer类型字段长度?

hibernate映射文件无法使用length指定int和Integer类型字段长度,正向生成的表中int和 Integer类型属性生成字段均为固定长度11
People.hbm.xml:

<hibernate-mapping package="com.wd.pojo">
        <class name="People" table="t_people">
            <id name="id"  column="id" length="5">
                <generator class="native"></generator>
            </id>
            <property name="age" length="5" column="age"></property>
            <property name="height" length="5"  column="height" type="java.lang.Integer"></property>
            <property name="name" length="20"></property>
        </class>
</hibernate-mapping>

生成的mysql数据库中的ddl:

CREATE TABLE `t_people` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `age` int(11) DEFAULT NULL,
  `height` int(11) DEFAULT NULL,
  `name` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

1个回答

我觉得int是没法控制长度的,因为int的范围本来就是固定的。如果你要控制一个字段的范围,估计只能用代码来判断的。

weixin_43317111
Steven-Russell 谢谢啦,我也是反复测试了,就是没法通过配置文件进行控制
2 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Hibernate怎样使用Annotation映射视图
<p>最近的项目中有几种用户,用户的字段差别极大,只有id、username、password、userType、name等几个相同的字段,现想做单点登录,采用视图方式,现在针对上面几个字段创建了一个普通视图,命名为View_User,没有主键。</p> <p>然后用MyEclipse的反射工程生成Annotation配置的实体类,共生成两个实体类,如下:</p> <p> </p> <pre name="code" class="java">ViewUser类</pre> <p> </p> <p> </p> <p> </p> <pre name="code" class="java">package com.ninemax.cul.user.entity; import javax.persistence.AttributeOverride; import javax.persistence.AttributeOverrides; import javax.persistence.Column; import javax.persistence.EmbeddedId; import javax.persistence.Entity; import javax.persistence.Table; /** * ViewUser entity. @author MyEclipse Persistence Tools */ @Entity @Table(name = "VIEW_USER") public class ViewUser implements java.io.Serializable { // Fields private ViewUserId id; // Constructors /** default constructor */ public ViewUser() { } /** full constructor */ public ViewUser(ViewUserId id) { this.id = id; } // Property accessors @EmbeddedId @AttributeOverrides({ @AttributeOverride(name = "id", column = @Column(name = "ID", length = 50)), @AttributeOverride(name = "username", column = @Column(name = "USERNAME", length = 32)), @AttributeOverride(name = "password", column = @Column(name = "PASSWORD", length = 32)), @AttributeOverride(name = "userType", column = @Column(name = "USER_TYPE")), @AttributeOverride(name = "name", column = @Column(name = "NAME", length = 65536)), @AttributeOverride(name = "isWorkFlag", column = @Column(name = "IS_WORK_FLAG")) }) public ViewUserId getId() { return this.id; } public void setId(ViewUserId id) { this.id = id; } }</pre> <p> 另外一个类是ViewUserId类:</p> <p> </p> <pre name="code" class="java">package com.ninemax.cul.user.entity; import javax.persistence.Column; import javax.persistence.Embeddable; /** * ViewUserId entity. @author MyEclipse Persistence Tools */ @Embeddable public class ViewUserId implements java.io.Serializable { // Fields private String id; private String username; private String password; private Integer userType; private String name; private Boolean isWorkFlag; // Constructors /** default constructor */ public ViewUserId() { } /** full constructor */ public ViewUserId(String id, String username, String password, Integer userType, String name, Boolean isWorkFlag) { this.id = id; this.username = username; this.password = password; this.userType = userType; this.name = name; this.isWorkFlag = isWorkFlag; } // Property accessors @Column(name = "ID", length = 50) public String getId() { return this.id; } public void setId(String id) { this.id = id; } @Column(name = "USERNAME", length = 32) public String getUsername() { return this.username; } public void setUsername(String username) { this.username = username; } @Column(name = "PASSWORD", length = 32) public String getPassword() { return this.password; } public void setPassword(String password) { this.password = password; } @Column(name = "USER_TYPE") public Integer getUserType() { return this.userType; } public void setUserType(Integer userType) { this.userType = userType; } @Column(name = "NAME", length = 65536) public String getName() { return this.name; } public void setName(String name) { this.name = name; } @Column(name = "IS_WORK_FLAG") public Boolean getIsWorkFlag() { return this.isWorkFlag; } public void setIsWorkFlag(Boolean isWorkFlag) { this.isWorkFlag = isWorkFlag; } public boolean equals(Object other) { // 省略 } public int hashCode() { // 省略 } }</pre> <p> 其实这样程序是可以运行的,问题在于视图中的name是可以为空的,在name为空时Hibernate加载不上来数据(为null),请问怎样才能让Hibernate将含有null字段值的记录也加载上来?</p> <p>网上有人介绍XML配置的解决方式,但我经验不足,没有参照着将Annotation下的解决办法找到,请各位指点一下,谢谢!</p>
hibernate中类not mapped问题
spring项目中,用到hibernate mapping。后台写完之后junit test可以跑通,数据库可以存取数据,但是页面数据传过来之后,hql报错。已经仔细检查过hql中是查询的是类名还是表名以及各项配置,hpl中查询的是map过的类名。单元测试跑得通,所以xml配置应该也没错。但是页面存取数据的时候会报错。仔细检查过hql的大小写,全半角以及空格是否为中文空格,依然不能解决问题。希望各路高人给指条明路,感激不尽。。 报错内容:[code=text] Caused by: org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [from User where userName=?] [/code] 具体的配置如下。 实体类:[code=java] package com.huatek.cloud.usercenter.entity; import com.huatek.framework.entity.FwAccount; public class User extends FwAccount{ private static final long serialVersionUID = 6736542524764495567L; private String seqNum; //数据的序列号,数据库中主键(id)。由于BaseServiceImpl中存在id字段,故重命名 private String userName; //用户名字段。如果注册方式为邮箱则它的值为email值;注册方式为手机则值为cellphone值 private String email; //用户的邮箱地址字段 private String cellphone; //用户的手机号字段 private int regType; //用户的注册类型字段 private String password; //用户的密码字段 private int activated; //用户的“是否激活”字段 private String validateCode; //用户的激活码字段 private java.sql.Timestamp registerTime; //用户的注册时间字段 //getter、setter方法略 } [/code] 类与表的映射文件:User.hbm.xml [code=text] import 实体类所在的package; <?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 = "com.huatek.cloud.usercenter.entity"> <class name = "User" table="t_register"> <id name="seqNum" type="java.lang.String" column="id" length="100"></id> <property name="userName" column="name" type="java.lang.String" length="30"></property> <property name="email" column="email" type="java.lang.String" length="50"></property> <property name="cellphone" column="phone" type="java.lang.String" length="11"></property> <property name="regType" column="regType" type="java.lang.Integer" length="1"></property> <property name="password" column="password" type="java.lang.String" length="50"></property> <property name="activated" column="status" type="java.lang.Integer" length="1"></property> <property name="validateCode" column="validateCode" type="java.lang.String" length="100"></property> <property name="registerTime" column="registerTime" type="java.sql.Timestamp" length="100"></property> </class> </hibernate-mapping> [/code] 配置映射文件:application-base.xml [code=text] <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="mappingLocations"> <list> <!-- base frame --> <value>classpath*:/com/huatek/framework/hibernate/maps/oracle/*.hbm.xml </value> <!-- data dictionary --> <value>classpath*:/com/huatek/dictionary/hibernate/oracle/*.hbm.xml </value> <!-- data authority --> <value>classpath*:/com/huatek/authority/hibernate/oracle/*.hbm.xml </value> <!-- cloud authority --> <value>classpath*:/com/huatek/cloud/usercenter/hibernate/mysql/*.hbm.xml </value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.show_sql">false</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.generate_statistics">false</prop> <prop key="hibernate.default_batch_fetch_size">30</prop> </props> </property> <!-- <property name="lobHandler"> <ref local="oracleLobHandler" /> </property> --> <property name="eventListeners"> <map> <entry key="merge"> <bean class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener" /> </entry> </map> </property> </bean> [/code] 服务层中的实现方法,实际是就是判断userName是否已经存在库中以实现判断用户名重复: [code=java] @Override public boolean cmpUserName(int regType, String userName) { String hql = "from User where userName=?"; @SuppressWarnings("unchecked") List<User> resultUser = hibernateTemplate.find(hql,userName); //每次debug单步跟进到这里报错 if (resultUser.isEmpty()) return userNameNotDup; else return userNameDup; } [/code]
新手求解一个hibernate3.6.10的问题
先贴代码: User类: public class User { private Integer id; private String nickName; private String password; private String familyName; private String name; private String fullName; private Boolean gender; private String nameStyle; private Date registerDate; private Date lastLoginDate; // getters和setters省略 } User.hbm.xml映射文件: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="org.maxwell.app.domain"> <class name="User" table="users" lazy="true"> <id name="id" column="user_id" length="11" type="int" > <generator class="identity" /> </id> <property name="nickName" column="nick_name" length="20" unique="true" not-null="true" /> <property name="password" length="20" not-null="true" /> <property name="familyName" column="family_name" length="20" /> <property name="name" length="20" /> <property name="gender" type="java.lang.Boolean" /> <property name="nameStyle" column="name_style" type="string" length="1" /> <property name="registerDate" type="timestamp" column="register_date" /> <property name="lastLoginDate" type="timestamp" column="last_login_date" /> <property name="fullName" formula="( select concat(u.family_name, u.name) from users u where u.user_id= id)" /> </class> </hibernate-mapping> 测试类: public class TestNews { public static void main(String[] args) { Configuration config = new Configuration().configure(); SessionFactory sf = config.buildSessionFactory(); Session session = sf.openSession(); Transaction tx = session.beginTransaction(); User u = new User().setNickName("Maxwell").setPassword("1234") .setFamilyName("张").setName("飞扬").setNameStyle("E") .setRegisterDate(new Date()).setLastLoginDate(new Date()); session.save(u); System.out.println(u); User u2 = (User) session.load(User.class, new Integer(1)); System.out.println(u2); tx.commit(); session.close(); sf.close(); } } 请问为什么会报出下面这样的错误呢? Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not load an entity: [org.maxwell.app.domain.User#1] at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) at org.hibernate.loader.Loader.loadEntity(Loader.java:2041) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:86) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:76) at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3294) at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:496) at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:477) at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:227) at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:147) at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1090) at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:1026) at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:176) at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:215) at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190) at org.maxwell.app.domain.User_$$_javassist_0.getFullName(User_$$_javassist_0.java) at org.maxwell.app.domain.TestNews.main(TestNews.java:25) Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'user0_.id' in 'where clause' at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:422) at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) at com.mysql.jdbc.Util.getInstance(Util.java:386) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4190) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4122) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2818) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2157) at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2324) at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208) at org.hibernate.loader.Loader.getResultSet(Loader.java:1953) at org.hibernate.loader.Loader.doQuery(Loader.java:802) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274) at org.hibernate.loader.Loader.loadEntity(Loader.java:2037) ... 14 more
hibernate3.3+mysql日期格式Date类型,无法进行相等的比较
hibernate3.3+mysql,数据库表是联合主键,其中一个为Date类型。此时对日期进行比较时,结果不正确。应该如何修改? 表结构: CREATE TABLE `temp` ( `room_id` int(11) NOT NULL, `priceDate` date NOT NULL, `value` varchar(20) DEFAULT NULL, PRIMARY KEY (`room_id`,`priceDate`) ); 映射文件: <composite-id name="id" class="com.boang.hotel.entity.TempId"> <key-property name="roomId" type="java.lang.Integer"> <column name="room_id" /> </key-property> <key-property name="priceDate" type="java.util.Date"> <column name="priceDate" length="10" /> </key-property> </composite-id> <property name="value" type="java.lang.String"> <column name="value" length="20" /> </property> 测试代码大致如下: Date tempDate = DateUtils.parseDate("2013-04-10"); TempId id = new TempId(1, tempDate); Temp temp = new Temp(id, "123"); save(temp); Temp savedTemp = load(Temp.class, id); System.out.println(savedTemp); ------预计结果------ Temp@***** ------实际结果------ null 测试代码里的save和load,都是直接使用的getHibernateTemplate()里的save和load。 日期转换DateUtils.parseDate是用的SimpleDateFormat将字符串转为日期,格式为yyyy-MM-dd。 为什么load不到结果呢?原有的数据库设计就是这样的,目前无法进行结构与类型的修改。 现在需要对这样的表进行批量新增与更新数据,这时hibernate会自动使用load方法去根据ID判断是否存在数据,如果load结果为null,就会进行插入,这时就会报错,主键唯一约束的错误。 请大家帮忙看看,有没有什么好的解决办法???
Spring集成Hibernate,使用JPA注解方式,新增数据无法提交
<div class="iteye-blog-content-contain" style="font-size: 14px;"> <p>环境:</p> <p style="padding-left: 60px;">spring 3.1</p> <p style="padding-left: 60px;">hibernate 4.2.8 final </p> <p style="padding-left: 60px;">mysql 5.6</p> <p>问题描述:</p> <p style="padding-left: 30px;">调用controller的查询方法,可以正常返回数据</p> <p style="padding-left: 30px;">调用controller的创建方法,即:新增数据,控制台打印出了读取和修改序号表的sql,但是没有打印插入数据的sql,数据库表中也没有新增数据。</p> <p style="padding-left: 30px;">怀疑是spring控制的事务没有提交,但是排查了两三天,从网上找了各种方法,都没有解决问题。</p> <p style="padding-left: 30px;">请各位大侠拉小弟一把,实在是找不到事务为什么没有提交。</p> <p> </p> <p style="padding-left: 30px;">web.xml</p> <p style="padding-left: 30px;"> </p> <pre name="code" class="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"&gt; &lt;!-- 欢迎界面 --&gt; &lt;welcome-file-list&gt; &lt;welcome-file&gt;index.html&lt;/welcome-file&gt; &lt;/welcome-file-list&gt; &lt;!-- spring框架 --&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;!-- 上下文配置 --&gt; &lt;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt; /WEB-INF/applicationContext.xml, /WEB-INF/config/**/*.xml &lt;/param-value&gt; &lt;/context-param&gt; &lt;!-- spring mvc --&gt; &lt;servlet&gt; &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt; &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt; &lt;!-- 拦截所有url --&gt; &lt;url-pattern&gt;/&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;!-- 回话有效期30分钟 --&gt; &lt;session-config&gt; &lt;session-timeout&gt;30&lt;/session-timeout&gt; &lt;/session-config&gt; &lt;!-- log4j日志 --&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.util.Log4jConfigListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;!-- log4j日志配置 --&gt; &lt;context-param&gt; &lt;param-name&gt;log4jConfigLocation&lt;/param-name&gt; &lt;param-value&gt;/WEB-INF/properties/log4j.properties&lt;/param-value&gt; &lt;/context-param&gt; &lt;/web-app&gt;</pre> <p> applicationContext.xml</p> <p> </p> <p style="padding-left: 30px;"> </p> <pre name="code" class="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt; &lt;!-- 注解配置 --&gt; &lt;context:annotation-config /&gt; &lt;!--允许使用注解方式配置事务 --&gt; &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt; &lt;!-- 自动扫描的包名 --&gt; &lt;context:component-scan base-package="com.lxl" /&gt; &lt;!-- 对标注@PersistenceContext的类经行增强,引入代理后的EntityManager实例 --&gt; &lt;bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /&gt; &lt;!-- 对标注@Repository的类经行增强,将EntityManager异常转换为SpringDAO体系的异常 --&gt; &lt;bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" /&gt; &lt;!-- 属性文件 --&gt; &lt;context:property-placeholder location="/WEB-INF/properties/**/*.properties" /&gt; &lt;!-- 数据源 --&gt; &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt; &lt;property name="driverClassName" value="${jdbc.driverClassName}" /&gt; &lt;property name="url" value="${jdbc.url}" /&gt; &lt;property name="username" value="${jdbc.username}" /&gt; &lt;property name="password" value="${jdbc.password}" /&gt; &lt;/bean&gt; &lt;!-- JPA 实体管理工厂 --&gt; &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt; &lt;property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" /&gt; &lt;property name="dataSource" ref="dataSource" /&gt; &lt;property name="persistenceUnitName" value="ServicePlatform" /&gt; &lt;property name="jpaVendorAdapter"&gt; &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt; &lt;property name="showSql" value="true" /&gt; &lt;property name="generateDdl" value="true" /&gt; &lt;property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect" /&gt; &lt;/bean&gt; &lt;/property&gt; &lt;/bean&gt; &lt;!-- JPA 事务管理 --&gt; &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt; &lt;property name="dataSource" ref="dataSource" /&gt; &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt; &lt;/bean&gt; &lt;/beans&gt;</pre> <p> dispatcher-servlet.xml</p> <p> </p> <p style="padding-left: 30px;"> </p> <pre name="code" class="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt; &lt;!-- 默认的注解映射的支持 --&gt; &lt;mvc:annotation-driven /&gt; &lt;!-- 自动扫描的包名 --&gt; &lt;context:component-scan base-package="com.lxl" /&gt; &lt;!-- 配置一下对json数据的转换 &lt;bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"&gt; &lt;property name="messageConverters"&gt; &lt;list&gt; &lt;bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"&gt;&lt;/bean&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; --&gt; &lt;!-- 视图解析器 --&gt; &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt; &lt;property name="prefix" value="/view" /&gt; &lt;property name="suffix" value=".jsp" /&gt; &lt;/bean&gt; &lt;!-- 对静态资源文件的访问 方案一 (二选一) --&gt; &lt;mvc:default-servlet-handler /&gt; &lt;!-- 对静态资源文件的访问 方案二 (二选一) &lt;mvc:resources mapping="/images/**" location="/images/" cache-period="31556926"/&gt; &lt;mvc:resources mapping="/js/**" location="/js/" cache-period="31556926"/&gt; &lt;mvc:resources mapping="/css/**" location="/css/" cache-period="31556926"/&gt; --&gt; &lt;/beans&gt;</pre> <p> </p> <p> </p> <p style="padding-left: 30px;">persistence.xml</p> <p style="padding-left: 30px;"> </p> <pre name="code" class="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"&gt; &lt;persistence-unit name="ServicePlatform" transaction-type="RESOURCE_LOCAL"&gt; &lt;/persistence-unit&gt; &lt;/persistence&gt; </pre> <p> </p> <p> </p> <p style="padding-left: 30px;">实体bean</p> <p style="padding-left: 30px;"> </p> <pre name="code" class="java">package com.lxl.bsp.identity.entity; import java.io.Serializable; import java.sql.Timestamp; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table(name = "bd_id") public class Identity implements Serializable { private static final long serialVersionUID = -8763611811485844772L; @Id @GeneratedValue(strategy = GenerationType.TABLE) private Long id; @Column(length = 100) private String code; private Long value; @Column(length = 10) private String prefix; @Column(length = 10) private String suffix; @Column(length = 255) private String description; private Integer length; @Column(length = 30) private String creator; @Column(name = "create_date") private Timestamp createDate; @Column(length = 30) private String modifier; @Column(name = "modify_Date") private Timestamp modifyDate; private Boolean dr; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } public Long getValue() { return value; } public void setValue(Long value) { this.value = value; } public String getPrefix() { return prefix; } public void setPrefix(String prefix) { this.prefix = prefix; } public String getSuffix() { return suffix; } public void setSuffix(String suffix) { this.suffix = suffix; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public Integer getLength() { return length; } public void setLength(Integer length) { this.length = length; } public String getCreator() { return creator; } public void setCreator(String creator) { this.creator = creator; } public Timestamp getCreateDate() { return createDate; } public void setCreateDate(Timestamp createDate) { this.createDate = createDate; } public String getModifier() { return modifier; } public void setModifier(String modifier) { this.modifier = modifier; } public Timestamp getModifyDate() { return modifyDate; } public void setModifyDate(Timestamp modifyDate) { this.modifyDate = modifyDate; } public Boolean getDr() { return dr; } public void setDr(Boolean dr) { this.dr = dr; } @Override public String toString() { return "Identity [id=" + id + ", code=" + code + ", value=" + value + ", prefix=" + prefix + ", suffix=" + suffix + ", description=" + description + ", length=" + length + ", creator=" + creator + ", createDate=" + createDate + ", modifier=" + modifier + ", modifyDate=" + modifyDate + ", dr=" + dr + "]"; } } </pre> <p> </p> <p> </p> <p style="padding-left: 30px;">IdentityDaoImpl.java</p> <p style="padding-left: 30px;"> </p> <pre name="code" class="java">package com.lxl.bsp.identity.dao; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import com.lxl.bsp.api.exception.ServicePlatformException; import com.lxl.bsp.identity.entity.Identity; @Repository public class IdentityDaoImpl implements IIdentityDao { @PersistenceContext private EntityManager em; @Transactional(propagation = Propagation.REQUIRED) public Identity create(Identity data) { em.persist(data); return data; } @Override public Identity retriver(String id) throws ServicePlatformException { Long pk = Long.valueOf(id); return em.find(Identity.class, pk); } @Override public Identity update(Identity data) throws ServicePlatformException { em.persist(data); return data; } @Override public void delete(String id) throws ServicePlatformException { em.remove(retriver(id)); } } </pre> <p> IdentityController.java</p> <p> </p> <p style="padding-left: 30px;"> </p> <pre name="code" class="java">package com.lxl.bsp.identity.controller; import java.sql.Timestamp; import java.util.Calendar; import javax.annotation.Resource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import com.lxl.bsp.api.exception.ServicePlatformException; import com.lxl.bsp.identity.dao.IIdentityDao; import com.lxl.bsp.identity.entity.Identity; @Controller @RequestMapping("identity") public class IdentityController { private static Log log = LogFactory.getLog(IdentityController.class); @Resource private IIdentityDao dao; @RequestMapping("retriver") @ResponseBody public Identity retriver(@RequestParam String id) throws ServicePlatformException { return dao.retriver(id); } @RequestMapping("create") @ResponseBody public Identity create() throws ServicePlatformException { int i = 1; Identity data = new Identity(); data.setCode("code" + i); Calendar c = Calendar.getInstance(); data.setCreateDate(new Timestamp(c.getTime().getTime())); data.setCreator("creator" + i); data.setDescription("description" + i); data.setDr(false); // data.setId("id" + Integer.toString(i)); data.setLength(30); data.setModifier("modifier" + i); data.setModifyDate(new Timestamp(c.getTime().getTime())); data.setPrefix("prefix"); data.setSuffix("suffix"); data.setValue(0L); Identity returnData = dao.create(data); log.debug(returnData); return returnData; } @RequestMapping("update") @ResponseBody public Identity update() throws ServicePlatformException { int i = 1; Identity data = new Identity(); data.setCode("1"); Calendar c = Calendar.getInstance(); data.setCreateDate(new Timestamp(c.getTime().getTime())); data.setCreator("creator" + i); data.setDescription("description" + i); data.setDr(false); // data.setId("id" + Integer.toString(i)); data.setLength(30); data.setModifier("modifier" + i); data.setModifyDate(new Timestamp(c.getTime().getTime())); data.setPrefix("prefix"); data.setSuffix("suffix"); data.setValue(0L); Identity returnData = dao.update(data); log.debug(returnData); return returnData; } @RequestMapping("delete") public void delete(@RequestParam String id) throws ServicePlatformException { dao.delete(id); } } </pre> <p> </p> <p> </p> <p style="padding-left: 30px;">数据表结构DDL</p> <p style="padding-left: 30px;"> </p> <pre name="code" class="sql">-- ---------------------------- -- Table structure for bd_id -- ---------------------------- DROP TABLE IF EXISTS `bd_id`; CREATE TABLE `bd_id` ( `id` bigint(30) NOT NULL, `code` varchar(100) DEFAULT NULL, `create_date` datetime DEFAULT NULL, `creator` varchar(30) DEFAULT NULL, `description` varchar(255) DEFAULT NULL, `dr` tinyint(1) DEFAULT NULL, `length` int(11) DEFAULT NULL, `modifier` varchar(30) DEFAULT NULL, `modify_Date` datetime DEFAULT NULL, `prefix` varchar(10) DEFAULT NULL, `suffix` varchar(10) DEFAULT NULL, `value` bigint(20) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;</pre> <p> </p> <p> </p> <p style="padding-left: 30px;">附件中是项目压缩包,只要电脑上安装了数据库,解压即可运行,数据库名称是osd</p> <p> </p> </div>
hibernate 查詢字段(SET)為null 的數據
我想要某個對象下某個集合屬性為空的搜索結果,在寫hql語句的時候測試了N次一直不成功:select c from Category c where c.childCategory is null childCategory 是一個 集合,報 Caused by: java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use 錯誤 請問應該怎樣修改 [b]问题补充:[/b] 這是一個映射自身的類,為一對多 一個類別可以有多個子類別:childCategory 【code="java"] package com.bookseat.entitys; import java.util.HashSet; import java.util.Set; public class Category { private Integer categoryId; private String categoryName; public Integer getCategoryId() { return categoryId; } public void setCategoryId(Integer categoryId) { this.categoryId = categoryId; } private Category fatherCategory; private Set<Category> childCategory = new HashSet<Category>(); private Set<Dishware> dishwaresByCategory = new HashSet<Dishware>(); public String getCategoryName() { return categoryName; } public void setCategoryName(String categoryName) { this.categoryName = categoryName; } public Set<Category> getChildCategory() { return childCategory; } public void setChildCategory(Set<Category> childCategory) { this.childCategory = childCategory; } public Set<Dishware> getDishwaresByCategory() { return dishwaresByCategory; } public void setDishwaresByCategory(Set<Dishware> dishwaresByCategory) { this.dishwaresByCategory = dishwaresByCategory; } public Category(String categoryName, Category fatherCategory, Set<Category> childCategory, Set<Dishware> dishwaresByCategory) { super(); this.categoryName = categoryName; this.fatherCategory = fatherCategory; this.childCategory = childCategory; this.dishwaresByCategory = dishwaresByCategory; } public Category getFatherCategory() { return fatherCategory; } public void setFatherCategory(Category fatherCategory) { this.fatherCategory = fatherCategory; } public Category() { } public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((categoryId == null) ? 0 : categoryId.hashCode()); result = prime * result + ((categoryName == null) ? 0 : categoryName.hashCode()); return result; } public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; final Category other = (Category) obj; if (categoryId == null) { if (other.categoryId != null) return false; } else if (!categoryId.equals(other.categoryId)) return false; if (categoryName == null) { if (other.categoryName != null) return false; } else if (!categoryName.equals(other.categoryName)) return false; return true; } } [/code] 配置文件: [code="xml"] <?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="com.bookseat.entitys"> <class name="Category"> <id name="categoryId" column="category_id"> <generator class="increment" /> </id> <property name="categoryName" not-null="true" length="50" column="Category_Name" /> <set name="dishwaresByCategory" table="dishware_categorytable" cascade="save-update" lazy="false" > <key column="categoryId" /> <many-to-many column="dishwareId" class="Dishware" /> </set> <many-to-one name="fatherCategory" class="Category" fetch="select" cascade="save-update"> <column name="Category_parentId" /> </many-to-one> <set name="childCategory" inverse="true" lazy="false" cascade="save-update"> <key> <column name="Category_parentId" /> </key> <one-to-many class="Category" /> </set> </class> </hibernate-mapping> [/code] 按照yayg 兄的寫了搜索,不報錯但是仍然為空
setResultTransformer(Transformers.aliasToBean(..))
以前一直用jdbc做开发,取出的数据放在为每个表建立的数据类中,想放表的哪几个字段就放哪几个 现在想学学hibernate,用oracle的原生sql想取出一个表中的两列: String selectTopicSql = "select topic,sectorname from article order by topic desc"; query = session.createSQLQuery(selectTopicSql1).setResultTransformer(Transformers.aliasToBean(Article.class)); Article.java就是hibernate对表ARTICLE的映射类,其配置文件如下: <?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="test"> <class name="Article" table="ARTICLE" > <meta attribute="sync-DAO">false</meta> <id name="topic" column="TOPIC" type="string"> <generator class="native"/> </id> <property name="Sectorname" column="SECTORNAME" type="string" not-null="true" length="40" /> <property name="Contents" column="CONTENTS" type="string" /> <property name="Keyword" column="KEYWORD" type="string" length="40" /> <property name="Source" column="SOURCE" type="string" length="100" /> <property name="Pageview" column="PAGEVIEW" type="integer" length="10" /> <property name="Score" column="SCORE" type="big_decimal" length="2" /> <property name="Createtime" column="CREATETIME" type="date" length="7" update="false" /> <property name="Updatetime" column="UPDATETIME" type="date" length="7" update="false" /> </class> </hibernate-mapping> 该配置文件在执行全字段检索没有问题,现在只取topic,sectorname就报错: Exception in thread "main" org.hibernate.PropertyNotFoundException: Could not find setter for TOPIC on class test.Article at org.hibernate.property.ChainedPropertyAccessor.getSetter(ChainedPropertyAccessor.java:68) at org.hibernate.transform.AliasToBeanResultTransformer.transformTuple(AliasToBeanResultTransformer.java:87) at org.hibernate.hql.HolderInstantiator.instantiate(HolderInstantiator.java:92) at org.hibernate.loader.custom.CustomLoader.getResultList(CustomLoader.java:353) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125) at org.hibernate.loader.Loader.list(Loader.java:2120) at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:312) at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1722) at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165) at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:175) at com.struts_learn.dao.ArticleDAO.selectTopic(ArticleDAO.java:58) at com.struts_learn.dao.ArticleDAO.main(ArticleDAO.java:206) 看了源码没看明白,如果另外再写一个jdbc那种数据类,何必用hibernate的映射类,如果不这样是不是就不能只取两个字段?我那个表的其他字段有很大的,不想全取出来,一直听说hibernate是持久层牛X框架,今日一见实在是失望,搞这么个东西在jdbc不用10分钟,竟然在hibernate里搞了半天也没能用映射类Article.java实现! 希望有对hibernate老手指点下! package test; import test.base.BaseArticle; import java.math.*; public class Article extends BaseArticle { private static final long serialVersionUID = 1L; /*[CONSTRUCTOR MARKER BEGIN]*/ public Article () { super(); } /** * Constructor for primary key */ public Article (java.lang.String topic) { super(topic); } /** * Constructor for required fields */ public Article ( java.lang.String topic, java.lang.String sectorname, java.lang.String contents, java.lang.String keyword, java.lang.String source, java.lang.Integer pageview, java.math.BigDecimal score, java.util.Date createtime, java.util.Date updatetime) { super ( topic, sectorname, contents, keyword, source, pageview, score, createtime, updatetime); } /*[CONSTRUCTOR MARKER END]*/ } package test.base; import java.io.Serializable; /** * This is an object that contains data related to the ARTICLE table. * Do not modify this class because it will be overwritten if the configuration file * related to this class is modified. * * @hibernate.class * table="ARTICLE" */ public abstract class BaseArticle implements Serializable { public static String REF = "Article"; public static String PROP_PAGEVIEW = "Pageview"; public static String PROP_KEYWORD = "Keyword"; public static String PROP_TOPIC = "Topic"; public static String PROP_UPDATETIME = "Updatetime"; public static String PROP_SCORE = "Score"; public static String PROP_CONTENTS = "Contents"; public static String PROP_CREATETIME = "Createtime"; public static String PROP_SOURCE = "Source"; public static String PROP_SECTORNAME = "Sectorname"; // constructors public BaseArticle () { initialize(); } /** * Constructor for primary key */ public BaseArticle (java.lang.String topic) { this.setTopic(topic); initialize(); } /** * Constructor for required fields */ public BaseArticle ( java.lang.String topic, java.lang.String sectorname, java.lang.String contents, java.lang.String keyword, java.lang.String source, java.lang.Integer pageview, java.math.BigDecimal score, java.util.Date createtime, java.util.Date updatetime) { this.setTopic(topic); this.setSectorname(sectorname); this.setContents(contents); this.setKeyword(keyword); this.setSource(source); this.setPageview(pageview); this.setScore(score); this.setCreatetime(createtime); this.setUpdatetime(updatetime); initialize(); } protected void initialize () {} private int hashCode = Integer.MIN_VALUE; // primary key private java.lang.String topic; // fields private java.lang.String sectorname; private java.lang.String contents; private java.lang.String keyword; private java.lang.String source; private java.lang.Integer pageview; private java.math.BigDecimal score; private java.util.Date createtime; private java.util.Date updatetime; /** * Return the unique identifier of this class * @hibernate.id * generator-class="native" * column="TOPIC" */ public java.lang.String getTopic () { return topic; } /** * Set the unique identifier of this class * @param topic the new ID */ public void setTopic (java.lang.String topic) { this.topic = topic; this.hashCode = Integer.MIN_VALUE; } /** * Return the value associated with the column: SECTORNAME */ public java.lang.String getSectorname () { return sectorname; } /** * Set the value related to the column: SECTORNAME * @param sectorname the SECTORNAME value */ public void setSectorname (java.lang.String sectorname) { this.sectorname = sectorname; } /** * Return the value associated with the column: CONTENTS */ public java.lang.String getContents () { return contents; } /** * Set the value related to the column: CONTENTS * @param contents the CONTENTS value */ public void setContents (java.lang.String contents) { this.contents = contents; } /** * Return the value associated with the column: KEYWORD */ public java.lang.String getKeyword () { return keyword; } /** * Set the value related to the column: KEYWORD * @param keyword the KEYWORD value */ public void setKeyword (java.lang.String keyword) { this.keyword = keyword; } /** * Return the value associated with the column: SOURCE */ public java.lang.String getSource () { return source; } /** * Set the value related to the column: SOURCE * @param source the SOURCE value */ public void setSource (java.lang.String source) { this.source = source; } /** * Return the value associated with the column: PAGEVIEW */ public java.lang.Integer getPageview () { return pageview; } /** * Set the value related to the column: PAGEVIEW * @param pageview the PAGEVIEW value */ public void setPageview (java.lang.Integer pageview) { this.pageview = pageview; } /** * Return the value associated with the column: SCORE */ public java.math.BigDecimal getScore () { return score; } /** * Set the value related to the column: SCORE * @param score the SCORE value */ public void setScore (java.math.BigDecimal score) { this.score = score; } /** * Return the value associated with the column: CREATETIME */ public java.util.Date getCreatetime () { return createtime; } /** * Set the value related to the column: CREATETIME * @param createtime the CREATETIME value */ public void setCreatetime (java.util.Date createtime) { this.createtime = createtime; } /** * Return the value associated with the column: UPDATETIME */ public java.util.Date getUpdatetime () { return updatetime; } /** * Set the value related to the column: UPDATETIME * @param updatetime the UPDATETIME value */ public void setUpdatetime (java.util.Date updatetime) { this.updatetime = updatetime; } public boolean equals (Object obj) { if (null == obj) return false; if (!(obj instanceof test.Article)) return false; else { test.Article article = (test.Article) obj; if (null == this.getTopic() || null == article.getTopic()) return false; else return (this.getTopic().equals(article.getTopic())); } } public int hashCode () { if (Integer.MIN_VALUE == this.hashCode) { if (null == this.getTopic()) return super.hashCode(); else { String hashStr = this.getClass().getName() + ":" + this.getTopic().hashCode(); this.hashCode = hashStr.hashCode(); } } return this.hashCode; } public String toString () { return super.toString(); } }
struts2 与Hibernate编程异常,求解决!!!
action里的代码如下:测试发现程序能够输出System.out.println(ChooseGoods[i]+"////");但 god = gdi.selectById(ChooseGoods[i]);没有执行,不知道为什么会停在这! Hibernate使用的标签,这里问什么会报映射异常呢.... 刚学习,望指导,谢谢! package com.action; import java.text.ParseException; import java.util.ArrayList; import java.util.List; import java.util.Map; import com.dao.imple.GoodsDaoImple; import com.dao.imple.GustorderDaoImple; import com.dao.imple.OrderDetailsDaoImple; import com.entity.Goods; import com.opensymphony.xwork2.ActionContext; public class OrderAction { GoodsDaoImple gdi = new GoodsDaoImple(); GustorderDaoImple odi = new GustorderDaoImple(); OrderDetailsDaoImple oddi = new OrderDetailsDaoImple(); private Goods god = new Goods(); private int[] gid; private String[] amount; private String name; private String address; private int[] ChooseGoods; public Goods getGod() { return god; } public void setGod(Goods god) { this.god = god; } public int[] getGid() { return gid; } public void setGid(int[] gid) { this.gid = gid; } public String[] getAmount() { return amount; } public void setAmount(String[] amount) { this.amount = amount; } private List<Goods> list = new ArrayList<Goods>() ; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public int[] getChooseGoods() { return ChooseGoods; } public void setChooseGoods(int[] chooseGoods) { ChooseGoods = chooseGoods; } public List<Goods> getList() { return list; } public void setList(List<Goods> list) { this.list = list; } public String execute(){ for (int i = 0;i<ChooseGoods.length;i++){ System.out.println(ChooseGoods.length); System.out.println(ChooseGoods[i]+"////"); god = gdi.selectById(ChooseGoods[i]); System.out.println("商品名称是:"+god.getGoodsname()); list.add(god); System.out.println("里面的list的长度是:"+list.size()); } System.out.println("list的长度是:"+list.size()); Map session = ActionContext.getContext().getSession(); session.put("list", list); return "success"; } 如下是错误: type Exception report message description The server encountered an internal error that prevented it from fulfilling this request. exception java.lang.reflect.InvocationTargetException sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:498) com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452) com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254) com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) ...........................................太多,后面的错误信息省了........................... ......................................... root cause java.lang.NoSuchMethodError: antlr.collections.AST.getLine()I org.hibernate.hql.ast.HqlSqlWalker.generatePositionalParameter(HqlSqlWalker.java:896) org.hibernate.hql.antlr.HqlSqlBaseWalker.parameter(HqlSqlBaseWalker.java:4819) ......................................... ....................................... ...........................................太多,后面的错误信息省了........................... note The full stack trace of the root cause is available in the Apache Tomcat/7.0.67 logs. 下面是查询方法的实体类: package com.entity; import java.util.HashSet; import java.util.Set; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import static javax.persistence.GenerationType.IDENTITY; import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.Table; /** * Goods entity. @author MyEclipse Persistence Tools */ @Entity @Table(name = "goods", catalog = "ordersystem") public class Goods implements java.io.Serializable { // Fields private Integer gid; private String goodsname; private Float goodsprice; private String goodsdesc; private String goodsmanufacturer; private Set<Orderdetails> orderdetailses = new HashSet<Orderdetails>(0); // Constructors /** default constructor */ public Goods() { } public Goods(Integer gid, String goodsname, Float goodsprice, String goodsdesc, String goodsmanufacturer) { super(); this.gid = gid; this.goodsname = goodsname; this.goodsprice = goodsprice; this.goodsdesc = goodsdesc; this.goodsmanufacturer = goodsmanufacturer; } /** minimal constructor */ public Goods(String goodsname, Float goodsprice) { this.goodsname = goodsname; this.goodsprice = goodsprice; } /** full constructor */ public Goods(String goodsname, Float goodsprice, String goodsdesc, String goodsmanufacturer, Set<Orderdetails> orderdetailses) { this.goodsname = goodsname; this.goodsprice = goodsprice; this.goodsdesc = goodsdesc; this.goodsmanufacturer = goodsmanufacturer; this.orderdetailses = orderdetailses; } // Property accessors @Id @GeneratedValue(strategy = IDENTITY) @Column(name = "gid", unique = true, nullable = false) public Integer getGid() { return this.gid; } public void setGid(Integer gid) { this.gid = gid; } @Column(name = "goodsname", nullable = false, length = 10) public String getGoodsname() { return this.goodsname; } public void setGoodsname(String goodsname) { this.goodsname = goodsname; } @Column(name = "goodsprice", nullable = false, precision = 12, scale = 0) public Float getGoodsprice() { return this.goodsprice; } public void setGoodsprice(Float goodsprice) { this.goodsprice = goodsprice; } @Column(name = "goodsdesc", length = 20) public String getGoodsdesc() { return this.goodsdesc; } public void setGoodsdesc(String goodsdesc) { this.goodsdesc = goodsdesc; } @Column(name = "goodsmanufacturer", length = 10) public String getGoodsmanufacturer() { return this.goodsmanufacturer; } public void setGoodsmanufacturer(String goodsmanufacturer) { this.goodsmanufacturer = goodsmanufacturer; } @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "goods") public Set<Orderdetails> getOrderdetailses() { return this.orderdetailses; } public void setOrderdetailses(Set<Orderdetails> orderdetailses) { this.orderdetailses = orderdetailses; } }
有些困惑,大家帮忙看看一对多映射时save的一个问题,多谢了!!!
我是在初学hibernate,是仿照书上的例子。我新建了下面两个关联的数据表。create table CUSTOMERS ( ID bigint not null, NAME varchar(15), AGE int, primary key (ID)); create table ORDERS ( ID bigint not null, ORDER_NUMBER varchar(15), PRICE double precision, CUSTOMER_ID bigint, primary key (ID)); alter table ORDERS add index IDX_CUSTOMER(CUSTOMER_ID), add constraint FK_CUSTOMER foreign key (CUSTOMER_ID) references CUSTOMERS (ID); 建立了下列hbm.xml <hibernate-mapping package="com.zl.model"> <class name="Customers" table="customers" > <id name="id" type="java.lang.Long"> <column name="ID" /> <generator class="assigned"></generator> </id> <property name="name" type="java.lang.String"> <column name="NAME" length="15" /> </property> <property name="age" type="java.lang.Integer"> <column name="AGE" /> </property> <set name="orderses" lazy="true" cascade="all" inverse="true"> <key> <column name="CUSTOMER_ID" not-null="true" /> </key> <one-to-many class="Orders" /> </set> </class> </hibernate-mapping> <hibernate-mapping package="com.zl.model"> <class name="Orders" table="orders" > <id name="id" type="java.lang.Long"> <column name="ID" /> <generator class="assigned"></generator> </id> <many-to-one name="customers" class="Customers" > <column name="CUSTOMER_ID" not-null="true" /> </many-to-one> <property name="orderNumber" type="java.lang.String"> <column name="ORDER_NUMBER" length="15" /> </property> <property name="price" type="java.lang.Double"> <column name="PRICE" precision="22" scale="0" /> </property> </class> </hibernate-mapping> 打开show-sql配置,然后调用下列代码,来测试 public static void main(String[] args) { Session session = HibernateSessionFactory.getSession(); Customers cust = (Customers)session.get(Customers.class, new Long(2)); Orders order = new Orders(); order.setId(4L); order.setCustomers(cust); order.setOrderNumber("zl000004"); cust.getOrderses().add(order); Transaction tran = session.beginTransaction(); System.out.println("before save!"); session.save(cust); System.out.println("after save!"); tran.commit(); } 按书上的说法,在tran.commit()时,hibernate只调用一条insert order的语句。 但我发现在调用session.save(cust)时,hibernate并没有调用sql语句。但在tran.commit()时,先执行了一条 select orders_.ID, 。。。。from orders orders_ where orders_.ID=4 再执行insert into orders ...sql语句的。但我看的所有hibernate的书上都没有提到会执行这个select语句的。 那这样执行程序时,效率不就很低了? 我要是执行session.save(order)的话,那就只有一条sql语句。 现在就很疑惑,为什么书上的例子很多都这样写。请过来人给解惑下,多谢了
一条HQL语句引起的异常
表结构: CREATE TABLE IF NOT EXISTS tb_cases( id int(11) NOT NULL auto_increment, cdate date default NULL, title varchar(50) default NULL, cont text, imgpath varchar(80) default NULL, apply text, PRIMARY KEY (id) )ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; Hibernate映射文件: <?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> <class name="com.base.hibernate.po.Cases" table="tb_cases"> <id name="id" type="java.lang.Integer"> <column name="id" /> <generator class="native" /> </id> <property name="cdate" type="java.util.Date"> <column name="cdate" length="10" /> </property> <property name="title" type="java.lang.String"> <column name="title" length="50" /> </property> <property name="content" type="java.lang.String"> <column name="cont" /> </property> <property name="imgpath" type="java.lang.String"> <column name="imgpath" length="50" /> </property> <property name="apply" type="java.lang.String"> <column name="apply" /> </property> </class> </hibernate-mapping> HQL语句: String FIND_CASENUM = " from Cases order by cdate desc "; 实现方法: public List<Cases> getCasesNum(final int showPage, final int pageSize){ return getHibernateTemplate().executeFind(new HibernateCallback() { public Object doInHibernate(final Session session) { Query query = session.createQuery(FIND_CASENUM); query.setFirstResult((showPage - 1) * pageSize); query.setMaxResults(pageSize); List<Cases> casesList = query.list(); if(null == casesList || casesList.isEmpty()){ casesList = null; } return casesList; } }); } 抛出异常: Hibernate: select top 4 cases0_.id as id1_, cases0_.cdate as cdate1_, cases0_.title as title1_, cases0_.cont as cont1_, cases0_.imgpath as imgpath1_, cases0_.apply as apply1_ from tb_cases cases0_ order by cases0_.cdate desc 2009-07-08 13:06:22,281 [org.hibernate.util.JDBCExceptionReporter]-[WARN] SQL Error: 1064, SQLState: 42000 2009-07-08 13:06:22,281 [org.hibernate.util.JDBCExceptionReporter]-[ERROR] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '4 cases0_.id as id1_, cases0_.cdate as cdate1_, cases0_.title as title1_, cases0' at line 1 2009-07-08 13:06:26,812 [org.apache.struts.action.RequestProcessor]-[WARN] Unhandled Exception thrown: class org.springframework.dao.InvalidDataAccessResourceUsageException 2009-07-08 13:06:26,812 [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/bianyaqi].[action]]-[ERROR] Servlet.service() for servlet action threw exception org.hibernate.exception.SQLGrammarException: could not execute query at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.loader.Loader.doList(Loader.java:2223) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104) at org.hibernate.loader.Loader.list(Loader.java:2099) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378) at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338) at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79) at com.base.hibernate.dao.impl.CasesDaoImpl$1.doInHibernate(CasesDaoImpl.java:65) at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:372) at org.springframework.orm.hibernate3.HibernateTemplate.executeFind(HibernateTemplate.java:342) at com.base.hibernate.dao.impl.CasesDaoImpl.getCasesNum(CasesDaoImpl.java:60) at com.base.spring.service.impl.CasesServiceImpl.getCasesNum(CasesServiceImpl.java:66) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:304) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:139) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at $Proxy1.getCasesNum(Unknown Source) at com.base.struts.action.IndexAction.execute(IndexAction.java:130) at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196) at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414) at javax.servlet.http.HttpServlet.service(HttpServlet.java:689) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at com.base.common.filter.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:123) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at com.base.common.filter.ForceNoCacheFilter.doFilter(ForceNoCacheFilter.java:36) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869) at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527) at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684) at java.lang.Thread.run(Thread.java:619) Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '4 cases0_.id as id1_, cases0_.cdate as cdate1_, cases0_.title as title1_, cases0' at line 1 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at com.mysql.jdbc.Util.handleNewInstance(Util.java:406) at com.mysql.jdbc.Util.getInstance(Util.java:381) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734) at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1885) at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186) at org.hibernate.loader.Loader.getResultSet(Loader.java:1787) at org.hibernate.loader.Loader.doQuery(Loader.java:674) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236) at org.hibernate.loader.Loader.doList(Loader.java:2220) ... 54 more 怀疑是HQL语句有什么错误,但愣是没找出来 映射文件与表中的字段名也检查过了,没什么问题啊! 查看了好久也没找出到底什么地方的错误 还请各们朋友们帮下忙看下到底怎么回事! 补充: 如果将HQL语句改成 from Product 问题依旧 但在Mysql数据库中使用 select id,cdate,title,cont,imgpath,apply from tb_cases; 语句没有任何错误!
struts2+spring2.5+hibernate整合的问题
<p>ssh整合的时候不报错,但插入的时候数据库也没有数据,控制台把insert语句已经打出来了,这是什么情况,请大侠们帮忙看看 <br><br><br>applicationContext.xml 配置如下:</p> <p> </p> <p>&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br>&lt;beans xmlns="<a href="http://www.springframework.org/schema/beans">http://www.springframework.org/schema/beans</a>"<br>xmlns:context="<a href="http://www.springframework.org/schema/context">http://www.springframework.org/schema/context</a>"<br>xmlns:tx="<a href="http://www.springframework.org/schema/tx">http://www.springframework.org/schema/tx</a>"<br>xmlns:aop="<a href="http://www.springframework.org/schema/aop">http://www.springframework.org/schema/aop</a>"<br> xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>"<br> xsi:schemaLocation="<a href="http://www.springframework.org/schema/beans">http://www.springframework.org/schema/beans</a><br><a href="http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">http://www.springframework.org/schema/beans/spring-beans-2.5.xsd</a><br><a href="http://www.springframework.org/schema/tx">http://www.springframework.org/schema/tx</a><br><a href="http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">http://www.springframework.org/schema/tx/spring-tx-2.5.xsd</a><br><a href="http://www.springframework.org/schema/aop">http://www.springframework.org/schema/aop</a><br><a href="http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">http://www.springframework.org/schema/aop/spring-aop-2.5.xsd</a><br><a href="http://www.springframework.org/schema/context">http://www.springframework.org/schema/context</a><br><a href="http://www.springframework.org/schema/context/spring-context-2.5.xsd">http://www.springframework.org/schema/context/spring-context-2.5.xsd</a><br>" default-autowire="byName" default-lazy-init="true"&gt;</p> <p> &lt;bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;<br>  &lt;property name="locations"&gt;<br>   &lt;list&gt;<br>    &lt;value&gt;classpath*:jdbc.properties&lt;/value&gt;<br>   &lt;/list&gt;<br>  &lt;/property&gt;<br> &lt;/bean&gt;<br> <br> &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;<br>  &lt;property name="driverClassName" value="${jdbc.driver}"/&gt;<br>  &lt;property name="url" value="${jdbc.url}"/&gt;<br>  &lt;property name="username" value="${jdbc.username}"/&gt;<br>  &lt;property name="password" value="${jdbc.password}"&gt;&lt;/property&gt;<br>  <br>  &lt;property name="initialSize" value="5" /&gt;<br>  &lt;property name="maxActive" value="100" /&gt;<br>  &lt;property name="maxIdle" value="30" /&gt;<br>  &lt;property name="maxWait" value="500" /&gt;<br>  &lt;property name="poolPreparedStatements" value="false" /&gt;<br>  &lt;property name="defaultAutoCommit" value="false" /&gt;<br> &lt;/bean&gt;<br> <br> &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt;<br>     &lt;property name="dataSource" ref="dataSource"/&gt;<br>     &lt;property name="mappingResources"&gt;<br>       &lt;list&gt;<br>         &lt;value&gt;com/demo/mapping/demo.hbm.xml&lt;/value&gt;<br>       &lt;/list&gt;<br>     &lt;/property&gt;<br>  &lt;property name="hibernateProperties"&gt;<br>   &lt;props&gt;<br>    &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.OracleDialect&lt;/prop&gt;<br>       &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;<br>   &lt;/props&gt;<br>  &lt;/property&gt;<br>  <br> &lt;/bean&gt;<br> <br> &lt;bean id="dDao" class="com.demo.dao.Impl.demoDaoImpl"&gt;<br>  &lt;property name="sessionFactory" ref="sessionFactory"&gt;&lt;/property&gt;<br> &lt;/bean&gt;<br> <br> &lt;bean id="dService" class="com.demo.service.Impl.demoServiceImpl"&gt;<br>  &lt;property name="dDao" ref="dDao"&gt;&lt;/property&gt;<br> &lt;/bean&gt;<br> &lt;bean id="txManage" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;  <br>     &lt;property name="sessionFactory" ref="sessionFactory"/&gt;  <br> &lt;/bean&gt;  </p> <p>&lt;/beans&gt;</p> <p> </p> <p>struts.xml 如下:</p> <p> </p> <p>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;<br>&lt;!DOCTYPE struts PUBLIC<br>    "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"<br>    "<a href="http://struts.apache.org/dtds/struts-2.1.7.dtd">http://struts.apache.org/dtds/struts-2.1.7.dtd</a>"&gt;<br>&lt;struts&gt;<br> &lt;package name="demo" namespace="/demo" extends="struts-default"&gt;<br>  &lt;action name="demo" class="com.demo.action.RegisterAction"&gt;<br>   &lt;result name="index"&gt;/demo/demo-index.jsp&lt;/result&gt;<br>   &lt;result name="add"&gt;/demo/demo-add.jsp&lt;/result&gt;<br>   &lt;result name="operate"&gt;/demo/demo-add.jsp&lt;/result&gt;<br>   &lt;result name="save" type="redirectAction"&gt;demo!index.action&lt;/result&gt;<br>   &lt;result name="update" type="redirectAction"&gt;demo!index.action&lt;/result&gt;<br>   &lt;result name="delete" type="redirectAction"&gt;demo!index.action&lt;/result&gt;<br>  &lt;/action&gt;<br> &lt;/package&gt;<br>&lt;/struts&gt;</p> <p> </p> <p>jdbc.properties  如下:</p> <p> </p> <p>jdbc.driver=oracle.jdbc.driver.OracleDriver<br>jdbc.url=jdbc:oracle:thin:@192.168.6.90:1521:orcl<br>jdbc.username=example<br>jdbc.password=123456<br>hibernate.dialect=org.hibernate.dialect.Oracle10gDialect</p> <p> </p> <p>web.xml   如下:</p> <p>&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br>&lt;web-app version="2.5" xmlns="<a href="http://java.sun.com/xml/ns/javaee">http://java.sun.com/xml/ns/javaee</a>"<br> xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>"<br> xsi:schemaLocation="<a href="http://java.sun.com/xml/ns/javaee">http://java.sun.com/xml/ns/javaee</a> <br> <a href="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd</a>"&gt;<br> <br>    &lt;context-param&gt;<br>   &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;<br>   &lt;param-value&gt;classpath:applicationContext.xml&lt;/param-value&gt;<br>    &lt;/context-param&gt;<br>  &lt;listener&gt;<br>      &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;<br>     &lt;/listener&gt;<br>  &lt;filter&gt;<br>   &lt;filter-name&gt;struts2Filter&lt;/filter-name&gt;<br>   &lt;filter-class&gt;org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter&lt;/filter-class&gt;<br>  &lt;/filter&gt;<br>  &lt;filter-mapping&gt;<br>   &lt;filter-name&gt;struts2Filter&lt;/filter-name&gt;<br>   &lt;url-pattern&gt;/*&lt;/url-pattern&gt;<br>  &lt;/filter-mapping&gt;<br>&lt;/web-app&gt;<br> </p> <p>dao  接口如下:</p> <p>package com.demo.dao;</p> <p>import java.io.Serializable;<br>import java.util.List;</p> <p>import com.demo.model.Demo;</p> <p>public interface demoDao {<br> <br> public void save(Demo demo);</p> <p> public List&lt;Demo&gt; getDemos(final String strHql,final Object...params);<br> <br> public List&lt;Demo&gt; getDemos();<br> <br> public void delete(Demo demo);<br> <br> public abstract &lt;T&gt; T findByPrimaryKey(Class&lt;T&gt; class1, Serializable serializable);<br> <br> public void update(Demo demo);<br>}</p> <p>dao的实现:</p> <p>package com.demo.dao.Impl;</p> <p>import java.io.Serializable;<br>import java.sql.SQLException;<br>import java.util.ArrayList;<br>import java.util.List;</p> <p>import org.hibernate.HibernateException;<br>import org.hibernate.Query;<br>import org.hibernate.Session;<br>import org.springframework.orm.hibernate3.HibernateCallback;<br>import org.springframework.orm.hibernate3.HibernateTemplate;<br>import org.springframework.orm.hibernate3.support.HibernateDaoSupport;<br>import org.springframework.transaction.annotation.Transactional;</p> <p>import com.demo.dao.demoDao;<br>import com.demo.model.Demo;</p> <p>public class demoDaoImpl  extends HibernateDaoSupport implements demoDao{</p> <p> @Transactional<br> public void save(Demo demo) {<br>  this.getHibernateTemplate().save(demo);<br> }</p> <p> @SuppressWarnings("unchecked")<br> public List&lt;Demo&gt; getDemos(final String strHql,final Object...params) {<br>  List&lt;Demo&gt; demos=new ArrayList&lt;Demo&gt;();<br>  demos=this.getHibernateTemplate().executeFind(new HibernateCallback() {<br>     public Object doInHibernate(Session session) throws HibernateException,SQLException {<br>      Query query=session.createQuery(strHql);<br>      for(int i=0;params!=null&amp;&amp;i&lt;params.length;i++){<br>       query.setString(i,params[i].toString());<br>      }<br>      return query.list();<br>   }<br>  });<br>  return demos;<br> }</p> <p> public void delete(Demo demo) {<br>  this.getHibernateTemplate().delete(demo);<br> }</p> <p>  @SuppressWarnings("unchecked")<br>  public &lt;T&gt; T findByPrimaryKey(Class&lt;T&gt; clazz, Serializable key) {<br>         T obj = (T) getSession().get(clazz, key);<br>         return obj;<br>     }</p> <p> public void update(Demo demo) {<br>  this.getHibernateTemplate().update(demo);<br> }</p> <p>  @SuppressWarnings("unchecked")<br> public List&lt;Demo&gt; getDemos() {<br>  return this.getHibernateTemplate().find("from Demo where 1=1");<br> }</p> <p> <br>}</p> <p>service接口:</p> <p>package com.demo.service;</p> <p>import java.io.Serializable;<br>import java.util.List;</p> <p>import com.demo.model.Demo;</p> <p>public interface demoService {<br> <br> public void save(Demo demo);<br> <br> public List&lt;Demo&gt; getDemos(final String strHql,final Object...params);<br> <br> public List&lt;Demo&gt; getDemos();<br> <br> public void delete(Demo demo);<br> <br> public &lt;T&gt; T findByPrimaryKey(Class&lt;T&gt; class1, Serializable serializable);<br> <br> public String createHql(Demo demo);<br> <br> public void update(Demo demo);<br>}</p> <p>service 的实现:</p> <p>package com.demo.service.Impl;</p> <p>import java.io.Serializable;<br>import java.util.List;</p> <p>import org.springframework.transaction.annotation.Transactional;</p> <p>import com.demo.dao.demoDao;<br>import com.demo.model.Demo;<br>import com.demo.service.demoService;</p> <p>public class demoServiceImpl implements demoService{</p> <p> private demoDao dDao;</p> <p> public demoDao getdDao() {<br>  return dDao;<br> }</p> <p> public void setdDao(demoDao dDao) {<br>  this.dDao = dDao;<br> }</p> <p> public void save(Demo demo) {<br>  dDao.save(demo);<br> }</p> <p> public List&lt;Demo&gt; getDemos(final String strHql,final Object...params) {<br>  return dDao.getDemos(strHql, params);<br> }</p> <p> public void delete(Demo demo) {<br>  dDao.delete(demo);<br> }</p> <p> @Override<br> public String createHql(Demo demo) {<br>  StringBuffer buf=new StringBuffer();<br>  buf.append("from Demo d where 1=1");<br>  if(demo!=null){<br>   buf.append("and d.name like '%"+demo.getName()+"%'");<br>  }<br>  return buf.toString();<br> }</p> <p> @Override<br> public &lt;T&gt; T findByPrimaryKey(Class&lt;T&gt; class1, Serializable serializable) {<br>  return dDao.findByPrimaryKey(class1, serializable);<br> }</p> <p> @Override<br> public void update(Demo demo) {<br>  dDao.update(demo);<br> }</p> <p> @Override<br> public List&lt;Demo&gt; getDemos() {<br>  return dDao.getDemos();<br> }<br>}<br><br>action 如下:</p> <p> </p> <p>package com.demo.action;</p> <p><br>import java.util.List;</p> <p>import com.demo.model.Demo;<br>import com.demo.service.demoService;</p> <p>public class RegisterAction {</p> <p> private Demo demo;<br> private demoService dService;<br> private List&lt;Demo&gt; demos;<br> <br> public Demo getDemo() {<br>  return demo;<br> }<br> public void setDemo(Demo demo) {<br>  this.demo = demo;<br> }<br> public demoService getdService() {<br>  return dService;<br> }<br> public void setdService(demoService dService) {<br>  this.dService = dService;<br> }<br> public List&lt;Demo&gt; getDemos() {<br>  return demos;<br> }</p> <p> public void setDemos(List&lt;Demo&gt; demos) {<br>  this.demos = demos;<br> }<br> <br> public String execute(){<br>  return "index";<br> }</p> <p> public String index(){<br>  //demos=dService.getDemos(dService.createHql(demo),null);<br>  demos=dService.getDemos();<br>  return "index";<br> }<br> public String add(){<br>  return "add";<br> }<br> public String operate(){<br>  demo=dService.findByPrimaryKey(Demo.class,demo.getId());<br>  return "operate";<br> }<br> public String save(){<br>  dService.save(demo);<br>  return "save";<br> }<br> public String delete(){<br>  demo=dService.findByPrimaryKey(Demo.class,demo.getId());<br>  dService.delete(demo);<br>  return "delete";<br> }<br> public String update(){<br>  demo=dService.findByPrimaryKey(Demo.class,demo.getId());<br>  demo.setName(demo.getName());<br>  demo.setAge(demo.getAge());<br>  demo.setAddress(demo.getAddress());<br>  dService.update(demo);<br>  return "update";<br> }<br>}</p> <p> 实体:</p> <p>package com.demo.model;</p> <p>public class Demo {</p> <p> private Long id;<br> private String name;<br> private Integer age;<br> private String address;<br> <br> public Long getId() {<br>  return id;<br> }<br> public void setId(Long id) {<br>  this.id = id;<br> }<br> public String getName() {<br>  return name;<br> }<br> public void setName(String name) {<br>  this.name = name;<br> }<br> public Integer getAge() {<br>  return age;<br> }<br> public void setAge(Integer age) {<br>  this.age = age;<br> }<br> public String getAddress() {<br>  return address;<br> }<br> public void setAddress(String address) {<br>  this.address = address;<br> }<br>}</p> <p>映射文件:demo.hbm.xml</p> <p>&lt;?xml version="1.0" encoding="utf-8"?&gt;<br>&lt;!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"<br>"<a href="http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd</a>"&gt;<br>&lt;!-- <br>    Mapping file autogenerated by MyEclipse Persistence Tools<br>--&gt;<br>&lt;hibernate-mapping package="com.demo.model"&gt;<br>    &lt;class name="Demo" table="tb_demo" catalog="example"&gt;<br>        &lt;id name="id" type="java.lang.Long"&gt;<br>            &lt;column name="id" /&gt;<br>            &lt;generator class="sequence"&gt;<br>             &lt;param name="sequence"&gt;seq_demo&lt;/param&gt;<br>            &lt;/generator&gt;<br>        &lt;/id&gt;<br>        &lt;property name="name" type="java.lang.String"&gt;<br>            &lt;column name="tb_name" length="50" not-null="true" unique="true" /&gt;<br>        &lt;/property&gt;<br>        &lt;property name="age" type="java.lang.Integer"&gt;<br>            &lt;column name="tb_age" /&gt;<br>        &lt;/property&gt;<br>        &lt;property name="address" type="java.lang.String"&gt;<br>            &lt;column name="tb_address" length="50" not-null="true" /&gt;<br>        &lt;/property&gt;<br>    &lt;/class&gt;<br>&lt;/hibernate-mapping&gt;</p> <p> </p> <p>页面:</p> <p>demo-add.jsp  如下 :</p> <p>&lt;%@ page pageEncoding="utf-8" contentType="text/html; charset=utf-8"%&gt;<br>&lt;%@ taglib uri="/struts-tags" prefix="s"%&gt;<br>&lt;html&gt;<br> &lt;head&gt;<br>  &lt;title&gt;ssh整合测试&lt;/title&gt;<br>  &lt;script type="text/javascript" src="/SSH1/js/jquery.js"&gt;&lt;/script&gt;<br> &lt;/head&gt;<br> &lt;body&gt;<br>  &lt;form method="post" action="demo/demo.action"&gt;<br>  &lt;input type="hidden" id="num" name="demo.id" value="${demo.id}"/&gt;<br>   &lt;table&gt;<br>    &lt;tr&gt;ssh整合数据测试&lt;/tr&gt;<br>    &lt;tr&gt;&lt;td align="right"&gt;姓名:&lt;/td&gt;&lt;td align="left"&gt;&lt;input type="text" name="demo.name" value="${demo.name}"/&gt;&lt;/td&gt;&lt;/tr&gt;<br>    &lt;tr&gt;&lt;td align="right"&gt;年龄:&lt;/td&gt;&lt;td align="left"&gt;&lt;input type="text" name="demo.age" value="${demo.age}"/&gt;&lt;/td&gt;&lt;/tr&gt;<br>    &lt;tr&gt;&lt;td align="right"&gt;家庭住址:&lt;/td&gt;&lt;td align="left"&gt;&lt;input type="text" name="demo.address" value="${demo.address}"/&gt;&lt;/td&gt;&lt;/tr&gt;<br>    &lt;tr&gt;&lt;td colspan="2"&gt;&lt;input type="button" value="保存" id="save"/&gt;&lt;input type="reset" value="重置"/&gt;&lt;/td&gt;&lt;/tr&gt;<br>   &lt;/table&gt;<br>  &lt;/form&gt;<br> &lt;/body&gt;<br>&lt;/html&gt;<br>&lt;script&gt;<br> $("document").ready(function (){<br>  $("#save").click(function(){<br>   if($("#num").val()==null||$("#num").val()==""){<br>    document.forms[0].action="/SSH1/demo/demo!save.action";<br>    document.forms[0].submit();<br>   }else{<br>    alert("eee");<br>    document.forms[0].action="/SSH1/demo/demo!update.action";<br>    document.forms[0].submit();<br>   }<br>  });<br> });<br>&lt;/script&gt;</p> <p> </p> <p>demo-index.jsp  如下:</p> <p>&lt;%@ page pageEncoding="utf-8" contentType="text/html; charset=utf-8"%&gt;<br>&lt;%@ taglib uri="/struts-tags" prefix="s"%&gt;<br>&lt;html&gt;<br> &lt;head&gt;<br>  &lt;title&gt;ssh整合测试&lt;/title&gt;<br> &lt;/head&gt;<br> &lt;body&gt;<br>  &lt;form action="demo/demo.action"&gt;<br>   &lt;table&gt;<br>    &lt;tr&gt;&lt;td&gt;&lt;a href="&lt;%=request.getContextPath() %&gt;/demo/demo!add.action"&gt;添加&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;<br>    &lt;tr&gt;&lt;td&gt;序号&lt;/td&gt;&lt;td&gt;姓名&lt;/td&gt;&lt;td&gt;年龄&lt;/td&gt;&lt;td&gt;地址&lt;/td&gt;&lt;td&gt;操作&lt;/td&gt;&lt;/tr&gt;<br>    &lt;s:if test="demos.size()&gt;0"&gt;<br>     &lt;s:iterator value="demos" status="st"&gt;<br>      &lt;tr&gt;<br>       &lt;td&gt;${st.index+1}&lt;/td&gt;<br>       &lt;td&gt;${name}&lt;/td&gt;<br>       &lt;td&gt;${age}&lt;/td&gt;<br>       &lt;td&gt;${address}&lt;/td&gt;<br>       &lt;td&gt;&lt;a href="&lt;%=request.getContextPath() %&gt;/demo/demo!operate.action?demo.id=${id}"&gt;修改&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a href="&lt;%=request.getContextPath() %&gt;/demo/demo!operate.action?demo.id=${id}"&gt;删除&lt;/a&gt;&lt;/td&gt;<br>      &lt;/tr&gt;<br>     &lt;/s:iterator&gt;<br>    &lt;/s:if&gt;<br>   &lt;/table&gt;<br>  &lt;/form&gt;<br> &lt;/body&gt;<br>&lt;/html&gt;</p>
java.sql.SQLException: Column 'gp_id' not found.
在hibernate中调用存储过程,其中我的存储过程编写如下: [code="java"] DELIMITER $$ DROP PROCEDURE IF EXISTS `qdrk`.`undobusiness`$$ CREATE DEFINER=`root`@`localhost` PROCEDURE `undobusiness`() BEGIN DECLARE business_date timestamp default current_timestamp; DECLARE mon int; SELECT business_date; SELECT max(plandate) into business_date from jz_business_plan; SELECT business_date; set mon = DATE_FORMAT(business_date,'%m'); WHILE (mon < DATE_FORMAT(Now(),'%m')) do insert into jz_business_plan(g_id,gb_id,account_id,bs_id) values(g_id,gb_id,account_id,bs_id); select g_id ,gb_id,account_id,bs_id from jz_gbmes where ((stday < date_format(Now(),'%d') and enday > date_format(Now(),'%d') and remindtype= '2') ; set mon = mon+1; end WHILE; SELECT * from jz_business_plan WHERE DATE_FORMAT(jz_business_plan.plandate,'%m') = DATE_FORMAT(now(),'%m'); END$$ DELIMITER ; [/code] hibernate的配置文件如下: [code="java"] hibernate-mapping> <class name="cn.qdrk.strive.model.JzBusinessPlan" table="jz_business_plan" catalog="qdrk"> <id name="gpId" type="java.lang.Integer"> <column name="gp_id" /> <generator class="native"></generator> </id> <many-to-one name="accountTable" class="cn.qdrk.strive.model.AccountTable" fetch="select"> <column name="account_id" /> </many-to-one> <many-to-one name="jzBusiness" class="cn.qdrk.strive.model.JzBusiness" fetch="select"> <column name="bs_id" /> </many-to-one> <many-to-one name="jzGuestbook" class="cn.qdrk.strive.model.JzGuestbook" fetch="select"> <column name="gb_id" /> </many-to-one> <many-to-one name="jzGbmes" class="cn.qdrk.strive.model.JzGbmes" fetch="select"> <column name="g_id" /> </many-to-one> <property name="plandate" type="java.util.Date"> <column name="plandate" length="19" not-null="true" /> </property> <property name="remark" type="java.lang.String"> <column name="remark" /> </property> </class> <sql-query name="undobusiness" callable="true"> <return alias="JzBusinessPlan" class="cn.qdrk.strive.model.JzBusinessPlan"> <return-property name="gp_id" column="gp_id"/> <return-property name="g_id" column="g_id" /> <return-property name="account_id" column="account_id"/> <return-property name="bs_id" column="bs_id" /> <return-property name="plandate" column="plandate" /> <return-property name="remark" column="remark" /> <return-property name="gb_id" column="gb_id" /> </return> {call undobusiness()} </sql-query> </hibernate-mapping> [/code] 错误信息如下: [code="java"] 2008-11-13 09:38:07,882 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 0, SQLState: S0022 2008-11-13 09:38:07,882 ERROR [org.hibernate.util.JDBCExceptionReporter] - Column 'gp_id' not found. org.hibernate.exception.SQLGrammarException: could not execute query at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.loader.Loader.doList(Loader.java:2148) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029) at org.hibernate.loader.Loader.list(Loader.java:2024) at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:111) at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1655) at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142) at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:164) at cn.qdrk.strive.dao.hibernate.CRMDaoHibernate.undoBusiness(CRMDaoHibernate.java:43) at cn.qdrk.strive.dao.hibernate.CRMDaoHibernate$$FastClassByCGLIB$$afe1117e.invoke(<generated>) at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149) at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:694) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149) [/code] [code="java"] Caused by: java.sql.SQLException: Column 'gp_id' not found. at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926) at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1093) at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2734) at org.apache.tomcat.dbcp.dbcp.DelegatingResultSet.getInt(DelegatingResultSet.java:237) at org.hibernate.type.IntegerType.get(IntegerType.java:28) at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:113) at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:102) at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:1088) at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:554) at org.hibernate.loader.Loader.doQuery(Loader.java:689) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224) at org.hibernate.loader.Loader.doList(Loader.java:2145) [/code] [b]问题补充:[/b] 我的jz_business_plan表中有这个键值的映射啊,至于二楼说的return-property name="gp_id" column="gp_id"/> 你的属性名不是gpId吗,改成gpId一样也会出现这样的问题。 [b]问题补充:[/b] [color=red]我调用存储过程call undobusiness();除了gp_id为4,plandate为当前时间,其他的列值都是null,难道是这方面的原因,哪么调用存储过程select g_id ,gb_id,account_id,bs_id from jz_gbmes where ((stday < date_format(Now(),'%d') and enday > date_format(Now(),'%d') and remindtype= '2') ;会列出数据,这样怎么修改呢?[/color] [b]问题补充:[/b] [color=red]E文没看懂,如果返回的是null,该怎么修改呢?万分感谢![/color] [b]问题补充:[/b] name属性是用来关联column的,我不用程序调用存储过程,在mysql命令行中调用call undobusiness();,会列出jz_business_plan的表中的内容,这张表会显示出列为:gp_id,g_id,remark,bs_id,gb_id,plandate,account_id,都会显示出来。
做了一个简单的SSH应用,但启动tomcat时总抛NoClassDefFoundError异常
做了一个简单的SSH应用,但启动tomcat时总抛NoClassDefFoundError异常。 <br />会有<pre name="code" class="java">java.lang.ClassNotFoundException: javax.transaction.TransactionManager</pre> <br />各位一定要帮看看啊!(ssh未入门级) <br /> <br />开发工具:Eclipse3.2+Tomcat5.5+Mysql5.0 <br />建表 <br /><pre name="code" class="java">CREATE TABLE `people` ( `id` int(11) NOT NULL auto_increment, `name` varchar(100) default NULL, `location` varchar(100) default NULL, PRIMARY KEY (`id`) ) </pre> <br /> <br />首先,建立工程和package,以下是我的工程目录 <br />  action <br />      DeletePeopleAction.java     //删除人员action <br />      EditPeopleAction.java         //编辑人员action第一步,读取需要修改的人员资料 <br />       EditPeopleActionDo.java   //修改人员action <br />      ListPeopleAction.javaSave   //显示人员列表action <br />      SavePeopleAction.java         //新增人员action <br />      SearchPeopleAction.java     //查找人员action <br />dao <br />      IDAO.java    //数据库操作接口 <br />       StudentDAOImpl.java  //数据库操作实现 <br />domain <br />      AbstractPeople.java   //实体抽象类 <br />       People.hbm.xml         //数据库映射 <br />       People.java                 //实体类 <br />service <br />      IService.java   //服务层接口 <br />       StudentManagerImpl.java   //服务层实现 <br />util <br />     Character.java   //字符编码过滤器 <br />      PageSupport.java   //分页 <br />applicationContext.xml   //Spring配置文件(hibernate部分和Service部分) <br /> <br />JSP:不详细些了。 <br />   addStudent.jsp <br />   editStudent.jsp <br />   searchList.jsp <br />   searchStudent.jsp <br />   studentList.jsp <br /> <br />我觉得问题就出在 Spring 的xml部署上, <br />或者是我引入的包有冲突,要么就是根本不对。 <br />下面是应用的配置信息: <br />1.web.xml <br /><pre name="code" class="java"><!----> &lt;web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemalocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"&gt; &lt;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;/WEB-INF/classes/applicationContext.xml&lt;/param-value&gt; &lt;/context-param&gt; &lt;resource-ref&gt; &lt;description&gt;SqlServer Datasource example&lt;/description&gt; &lt;res-ref-name&gt;jdbc/StudentManager&lt;/res-ref-name&gt; &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt; &lt;res-auth&gt;Container&lt;/res-auth&gt; &lt;/resource-ref&gt; &lt;filter&gt; &lt;filter-name&gt;hibernateFilter&lt;/filter-name&gt; &lt;filter-class&gt; org.springframework.orm.hibernate3.support.OpenSessionInViewFilter &lt;/filter-class&gt; &lt;init-param&gt; &lt;param-name&gt;singleSession&lt;/param-name&gt; &lt;param-value&gt;true&lt;/param-value&gt; &lt;/init-param&gt; &lt;/filter&gt; &lt;filter-mapping&gt; &lt;filter-name&gt;hibernateFilter&lt;/filter-name&gt; &lt;url-pattern&gt;*.do&lt;/url-pattern&gt; &lt;/filter-mapping&gt; &lt;servlet&gt; &lt;servlet-name&gt;SpringContextServlet&lt;/servlet-name&gt; &lt;servlet-class&gt; org.springframework.web.context.ContextLoaderServlet&lt;/servlet-class&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet&gt; &lt;servlet-name&gt;SpringLog4jConfigServlet&lt;/servlet-name&gt; &lt;servlet-class&gt; org.springframework.web.util.Log4jConfigServlet &lt;/servlet-class&gt; &lt;/servlet&gt; &lt;servlet&gt; &lt;servlet-name&gt;web&lt;/servlet-name&gt; &lt;servlet-class&gt; org.springframework.web.servlet.DispatcherServlet &lt;/servlet-class&gt; &lt;/servlet&gt; &lt;servlet&gt; &lt;servlet-name&gt;action&lt;/servlet-name&gt; &lt;servlet-class&gt;org.apache.struts.action.ActionServlet&lt;/servlet-class&gt; &lt;init-param&gt; &lt;param-name&gt;config&lt;/param-name&gt; &lt;param-value&gt;/WEB-INF/struts-config.xml&lt;/param-value&gt; &lt;/init-param&gt; &lt;init-param&gt; &lt;param-name&gt;debug&lt;/param-name&gt; &lt;param-value&gt;2&lt;/param-value&gt; &lt;/init-param&gt; &lt;init-param&gt; &lt;param-name&gt;detail&lt;/param-name&gt; &lt;param-value&gt;2&lt;/param-value&gt; &lt;/init-param&gt; &lt;load-on-startup&gt;2&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;action&lt;/servlet-name&gt; &lt;url-pattern&gt;*.do&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;welcome-file-list&gt; &lt;welcome-file&gt;/WEB-INF/jsp/index.jsp&lt;/welcome-file&gt; &lt;/welcome-file-list&gt; &lt;taglib&gt; &lt;taglib-uri&gt;/WEB-INF/struts-bean.tld&lt;/taglib-uri&gt; &lt;taglib-location&gt;/WEB-INF/struts-bean.tld&lt;/taglib-location&gt; &lt;/taglib&gt; &lt;taglib&gt; &lt;taglib-uri&gt;/WEB-INF/struts-html.tld&lt;/taglib-uri&gt; &lt;taglib-location&gt;/WEB-INF/struts-html.tld&lt;/taglib-location&gt; &lt;/taglib&gt; &lt;taglib&gt; &lt;taglib-uri&gt;/WEB-INF/struts-logic.tld&lt;/taglib-uri&gt; &lt;taglib-location&gt;/WEB-INF/struts-logic.tld&lt;/taglib-location&gt; &lt;/taglib&gt; &lt;taglib&gt; &lt;taglib-uri&gt;/WEB-INF/struts-nested.tld&lt;/taglib-uri&gt; &lt;taglib-location&gt;/WEB-INF/struts-nested.tld&lt;/taglib-location&gt; &lt;/taglib&gt; &lt;/web-app&gt; </pre> <br /> <br />2.struts-config.xml <br /><pre name="code" class="java"><!----> &lt;struts-config&gt; &lt;data-sources&gt; &lt;form-beans&gt; &lt;form-bean name="people" type="domain.People"&gt;&lt;/form-bean&gt; &lt;/form-beans&gt; &lt;global-exceptions&gt; &lt;global-forwards&gt; &lt;action-mappings&gt; &lt;action path="/savePeople" name="people" type="action.SavePeopleAction" scope="session" parameter="method"&gt; &lt;forward name="success" path="/listPeople.do"&gt;&lt;/forward&gt; &lt;/action&gt; &lt;action path="/listPeople" name="people" type="action.ListPeopleAction"&gt; &lt;forward name="success" path="/studentList.jsp"&gt;&lt;/forward&gt; &lt;/action&gt; &lt;action path="/deletePeople" name="people" type="action.DeletePeopleAction"&gt; &lt;forward name="success" path="/studentList.jsp"&gt;&lt;/forward&gt; &lt;/action&gt; &lt;action path="/editPeople" name="people" type="action.EditPeopleAction"&gt; &lt;forward name="success" path="/editStudent.jsp"&gt;&lt;/forward&gt; &lt;/action&gt; &lt;action path="/editPeopleDo" name="people" type="action.EditPeopleActionDo"&gt; &lt;forward name="success" path="/studentList.jsp"&gt;&lt;/forward&gt; &lt;/action&gt; &lt;action path="/searchPeople" name="people" type="action.SearchPeopleAction"&gt; &lt;forward name="success" path="/searchList.jsp"&gt;&lt;/forward&gt; &lt;/action&gt; &lt;action path="/test" name="people" type="action.Test"&gt;&lt;/action&gt; &lt;/action-mappings&gt; &lt;controller locale="true"&gt; &lt;message-resources parameter=""&gt; <!----> &lt;/struts-config&gt; </pre> <br /> <br /> <br />3.applicationContext.xml <br /><pre name="code" class="java"><!----> &lt;beans&gt; <!----> &lt;bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" depends-on="sessionFactory"&gt; &lt;property name="sessionFactory"&gt; &lt;ref bean="sessionFactory"&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="studentManager" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"&gt; &lt;property name="transactionManager"&gt; &lt;ref bean="transactionManager"&gt;&lt;/ref&gt; &lt;/property&gt; &lt;property name="target"&gt; &lt;bean class="service.StudentManagerImpl"&gt; &lt;property name="studentDAO"&gt; &lt;ref bean="StudentDAO"&gt; &lt;/property&gt; &lt;/bean&gt; &lt;/property&gt; &lt;property name="transactionAttributes"&gt; &lt;props&gt; &lt;prop key="save*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt; &lt;prop key="list*"&gt;PROPAGATION_REQUIRED,readOnly&lt;/prop&gt; &lt;prop key="delete*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt; &lt;prop key="get*"&gt;PROPAGATION_REQUIRED,readOnly&lt;/prop&gt; &lt;prop key="edit*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt; &lt;prop key="search*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;property name="proxyTargetClass"&gt; &lt;value&gt;true&lt;/value&gt; &lt;/property&gt; &lt;/bean&gt; <!----> &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt; &lt;property name="driverClassName"&gt; &lt;value&gt;com.mysql.jdbc.Driver&lt;/value&gt; &lt;/property&gt; &lt;property name="url"&gt; &lt;value&gt;jdbc:mysql://localhost:3306/dbjee&lt;/value&gt; &lt;/property&gt; &lt;property name="username"&gt; &lt;value&gt;root&lt;/value&gt; &lt;/property&gt; &lt;property name="password"&gt; &lt;value&gt;123456&lt;/value&gt; &lt;/property&gt; &lt;/bean&gt; <!----> &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt; &lt;property name="dataSource"&gt; &lt;ref local="dataSource"&gt; &lt;/property&gt; &lt;property name="hibernateProperties"&gt; &lt;props&gt; &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt; &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt; &lt;prop key="hibernate.cache.use_query_cache"&gt;true&lt;/prop&gt; &lt;prop key="hibernate.cache.provider_class"&gt; org.hibernate.cache.HashtableCacheProvider&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; <!----> &lt;property name="mappingResources"&gt; &lt;list&gt; &lt;value&gt;domain/People.hbm.xml&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="StudentDAO" class="dao.StudentDAOImpl"&gt; &lt;property name="sessionFactory"&gt; &lt;ref local="sessionFactory"&gt; &lt;/property&gt; &lt;/bean&gt; &lt;/beans&gt; </pre> <br /> <br />4.People.hbm.xml <br /><pre name="code" class="java"><!----> <!----> &lt;hibernate-mapping package="domain"&gt; &lt;class name="People" table="people"&gt; &lt;id name="id" type="java.lang.Integer"&gt; &lt;column name="id"&gt; &lt;generator class="increment"&gt;&lt;/generator&gt; &lt;/id&gt; &lt;property name="name" type="java.lang.String"&gt; &lt;column name="name" length="100"&gt; &lt;/property&gt; &lt;property name="location" type="java.lang.String"&gt; &lt;column name="location" length="100"&gt; &lt;/property&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </pre> <br /> <br /> <br /><span style="font-size: large;">附件里是我引入的jar包。 <br />希望各位能帮帮忙,困扰我2天,一直出不来。</span> <br /> <br />最后把启动Tomcat时报的错误也贴出来。 <br /><pre name="code" class="java">严重: Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/classes/applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/transaction/TransactionManager java.lang.NoClassDefFoundError: javax/transaction/TransactionManager at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Unknown Source) at java.lang.Class.getDeclaredMethods(Unknown Source) at java.beans.Introspector$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.beans.Introspector.getPublicDeclaredMethods(Unknown Source) at java.beans.Introspector.getTargetMethodInfo(Unknown Source) at java.beans.Introspector.getBeanInfo(Unknown Source) at java.beans.Introspector.getBeanInfo(Unknown Source) at org.springframework.beans.CachedIntrospectionResults.&lt;init&gt;(CachedIntrospectionResults.java:149) at org.springframework.beans.CachedIntrospectionResults.forClass(CachedIntrospectionResults.java:85) at org.springframework.beans.BeanWrapperImpl.setIntrospectionClass(BeanWrapperImpl.java:234) at org.springframework.beans.BeanWrapperImpl.setWrappedInstance(BeanWrapperImpl.java:192) at org.springframework.beans.BeanWrapperImpl.setWrappedInstance(BeanWrapperImpl.java:176) at org.springframework.beans.BeanWrapperImpl.&lt;init&gt;(BeanWrapperImpl.java:129) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:491) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:366) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:144) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:330) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:144) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:283) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:321) at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:139) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:252) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:190) at org.springframework.web.context.ContextLoaderServlet.init(ContextLoaderServlet.java:83) at javax.servlet.GenericServlet.init(GenericServlet.java:212) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1139) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:966) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3956) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4230) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544) at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:626) at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:553) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:488) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1150) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022) at org.apache.catalina.core.StandardHost.start(StandardHost.java:736) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443) at org.apache.catalina.core.StandardService.start(StandardService.java:448) at org.apache.catalina.core.StandardServer.start(StandardServer.java:700) at org.apache.catalina.startup.Catalina.start(Catalina.java:552) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433) Caused by: java.lang.ClassNotFoundException: javax.transaction.TransactionManager at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1386) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1232) at java.lang.ClassLoader.loadClassInternal(Unknown Source) ... 55 more 2008-11-14 20:08:31 org.apache.catalina.core.ApplicationContext log 严重: StandardWrapper.Throwable org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/classes/applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/transaction/TransactionManager java.lang.NoClassDefFoundError: javax/transaction/TransactionManager at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Unknown Source) at java.lang.Class.getDeclaredMethods(Unknown Source) at java.beans.Introspector$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.beans.Introspector.getPublicDeclaredMethods(Unknown Source) at java.beans.Introspector.getTargetMethodInfo(Unknown Source) at java.beans.Introspector.getBeanInfo(Unknown Source) at java.beans.Introspector.getBeanInfo(Unknown Source) at org.springframework.beans.CachedIntrospectionResults.&lt;init&gt;(CachedIntrospectionResults.java:149) at org.springframework.beans.CachedIntrospectionResults.forClass(CachedIntrospectionResults.java:85) at org.springframework.beans.BeanWrapperImpl.setIntrospectionClass(BeanWrapperImpl.java:234) at org.springframework.beans.BeanWrapperImpl.setWrappedInstance(BeanWrapperImpl.java:192) at org.springframework.beans.BeanWrapperImpl.setWrappedInstance(BeanWrapperImpl.java:176) at org.springframework.beans.BeanWrapperImpl.&lt;init&gt;(BeanWrapperImpl.java:129) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:491) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:366) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:144) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:330) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:144) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:283) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:321) at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:139) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:252) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:190) at org.springframework.web.context.ContextLoaderServlet.init(ContextLoaderServlet.java:83) at javax.servlet.GenericServlet.init(GenericServlet.java:212) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1139) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:966) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3956) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4230) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544) at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:626) at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:553) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:488) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1150) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022) at org.apache.catalina.core.StandardHost.start(StandardHost.java:736) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443) at org.apache.catalina.core.StandardService.start(StandardService.java:448) at org.apache.catalina.core.StandardServer.start(StandardServer.java:700) at org.apache.catalina.startup.Catalina.start(Catalina.java:552) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433) Caused by: java.lang.ClassNotFoundException: javax.transaction.TransactionManager at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1386) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1232) at java.lang.ClassLoader.loadClassInternal(Unknown Source) ... 55 more 2008-11-14 20:08:31 org.apache.catalina.core.StandardContext loadOnStartup 严重: Servlet /SSHDemo threw load() exception java.lang.ClassNotFoundException: javax.transaction.TransactionManager at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1386) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1232) at java.lang.ClassLoader.loadClassInternal(Unknown Source) at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Unknown Source) at java.lang.Class.getDeclaredMethods(Unknown Source) at java.beans.Introspector$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.beans.Introspector.getPublicDeclaredMethods(Unknown Source) at java.beans.Introspector.getTargetMethodInfo(Unknown Source) at java.beans.Introspector.getBeanInfo(Unknown Source) at java.beans.Introspector.getBeanInfo(Unknown Source) at org.springframework.beans.CachedIntrospectionResults.&lt;init&gt;(CachedIntrospectionResults.java:149) at org.springframework.beans.CachedIntrospectionResults.forClass(CachedIntrospectionResults.java:85) at org.springframework.beans.BeanWrapperImpl.setIntrospectionClass(BeanWrapperImpl.java:234) at org.springframework.beans.BeanWrapperImpl.setWrappedInstance(BeanWrapperImpl.java:192) at org.springframework.beans.BeanWrapperImpl.setWrappedInstance(BeanWrapperImpl.java:176) at org.springframework.beans.BeanWrapperImpl.&lt;init&gt;(BeanWrapperImpl.java:129) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:491) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:366) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:144) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:330) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:144) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:283) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:321) at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:139) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:252) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:190) at org.springframework.web.context.ContextLoaderServlet.init(ContextLoaderServlet.java:83) at javax.servlet.GenericServlet.init(GenericServlet.java:212) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1139) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:966) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3956) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4230) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544) at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:626) at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:553) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:488) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1150) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022) at org.apache.catalina.core.StandardHost.start(StandardHost.java:736) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443) at org.apache.catalina.core.StandardService.start(StandardService.java:448) at org.apache.catalina.core.StandardServer.start(StandardServer.java:700) at org.apache.catalina.startup.Catalina.start(Catalina.java:552) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433) 2008-11-14 20:08:32 org.apache.coyote.http11.Http11BaseProtocol start 信息: Starting Coyote HTTP/1.1 on http-8888 2008-11-14 20:08:32 org.apache.jk.common.ChannelSocket init </pre><br /><strong>问题补充</strong><br /><div class="quote_title">zzxplayful 写道</div><div class="quote_div">没有这个包 <br />java.lang.ClassNotFoundException: javax.transaction.TransactionManager  </div> <br />这段异常我看得懂, <br />包括下面的: <br /><pre name="code" class="java">org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/classes/applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/transaction/TransactionManager</pre> <br /> <br />都看得懂,我想知道的是解决办法。 <br />比如 <br />javax.transaction.TransactionManager <br />在什么包里? <br />要怎样解决?<br /><strong>问题补充</strong><br /><div class="quote_title">fywcc 写道</div><div class="quote_div">这个是spring里面的  你把SPRING的jar包重新覆盖进去试试</div> <br /> <br />我在Spring包里看了啊, <br />源码都是以 org.springframework.×××× 开始的啊, <br />没有 javax.transcation.** 啊, <br />怎么办?还是需要什么别的包,要么是我的包冲突了。 <br /> <br />我引入了: <br />antlr <br />commons-beanutils.jar <br />commons-digester.jar <br />commons-fileupload.jar <br />commons-logging.jar <br />commons-validator.jar <br />jakarta-oro.jar <br />struts.jar <br /> <br />spring.jar <br /> <br />hibernate3.jar<br /><strong>问题补充</strong><br /><div class="quote_title">jones 写道</div><div class="quote_div">放入jta.jar就行了,找找吧,spring里面应该有,要不就是Hibernate里面有</div> <br />谢谢你。 <br />我把缺少的包都放上了,终于启动Tomcat时候不抛异常,而且也能打开welcome页面了。 <br /> <br />但还有其他问题,明天搞。 <br /> <br />第一次搞SSH,多谢指点啊!
爬虫福利二 之 妹子图网MM批量下载
爬虫福利一:27报网MM批量下载    点击 看了本文,相信大家对爬虫一定会产生强烈的兴趣,激励自己去学习爬虫,在这里提前祝:大家学有所成! 目标网站:妹子图网 环境:Python3.x 相关第三方模块:requests、beautifulsoup4 Re:各位在测试时只需要将代码里的变量 path 指定为你当前系统要保存的路径,使用 python xxx.py 或IDE运行即可。
Java学习的正确打开方式
在博主认为,对于入门级学习java的最佳学习方法莫过于视频+博客+书籍+总结,前三者博主将淋漓尽致地挥毫于这篇博客文章中,至于总结在于个人,实际上越到后面你会发现学习的最好方式就是阅读参考官方文档其次就是国内的书籍,博客次之,这又是一个层次了,这里暂时不提后面再谈。博主将为各位入门java保驾护航,各位只管冲鸭!!!上天是公平的,只要不辜负时间,时间自然不会辜负你。 何谓学习?博主所理解的学习,它
程序员必须掌握的核心算法有哪些?
由于我之前一直强调数据结构以及算法学习的重要性,所以就有一些读者经常问我,数据结构与算法应该要学习到哪个程度呢?,说实话,这个问题我不知道要怎么回答你,主要取决于你想学习到哪些程度,不过针对这个问题,我稍微总结一下我学过的算法知识点,以及我觉得值得学习的算法。这些算法与数据结构的学习大多数是零散的,并没有一本把他们全部覆盖的书籍。下面是我觉得值得学习的一些算法以及数据结构,当然,我也会整理一些看过
大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了
大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、PDF搜索网站推荐 对于大部
linux系列之常用运维命令整理笔录
本博客记录工作中需要的linux运维命令,大学时候开始接触linux,会一些基本操作,可是都没有整理起来,加上是做开发,不做运维,有些命令忘记了,所以现在整理成博客,当然vi,文件操作等就不介绍了,慢慢积累一些其它拓展的命令,博客不定时更新 顺便拉下票,我在参加csdn博客之星竞选,欢迎投票支持,每个QQ或者微信每天都可以投5票,扫二维码即可,http://m234140.nofollow.ax.
比特币原理详解
一、什么是比特币 比特币是一种电子货币,是一种基于密码学的货币,在2008年11月1日由中本聪发表比特币白皮书,文中提出了一种去中心化的电子记账系统,我们平时的电子现金是银行来记账,因为银行的背后是国家信用。去中心化电子记账系统是参与者共同记账。比特币可以防止主权危机、信用风险。其好处不多做赘述,这一层面介绍的文章很多,本文主要从更深层的技术原理角度进行介绍。 二、问题引入  假设现有4个人
程序员接私活怎样防止做完了不给钱?
首先跟大家说明一点,我们做 IT 类的外包开发,是非标品开发,所以很有可能在开发过程中会有这样那样的需求修改,而这种需求修改很容易造成扯皮,进而影响到费用支付,甚至出现做完了项目收不到钱的情况。 那么,怎么保证自己的薪酬安全呢? 我们在开工前,一定要做好一些证据方面的准备(也就是“讨薪”的理论依据),这其中最重要的就是需求文档和验收标准。一定要让需求方提供这两个文档资料作为开发的基础。之后开发
网页实现一个简单的音乐播放器(大佬别看。(⊙﹏⊙))
今天闲着无事,就想写点东西。然后听了下歌,就打算写个播放器。 于是乎用h5 audio的加上js简单的播放器完工了。 欢迎 改进 留言。 演示地点跳到演示地点 html代码如下`&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;music&lt;/title&gt; &lt;meta charset="utf-8"&gt
Python十大装B语法
Python 是一种代表简单思想的语言,其语法相对简单,很容易上手。不过,如果就此小视 Python 语法的精妙和深邃,那就大错特错了。本文精心筛选了最能展现 Python 语法之精妙的十个知识点,并附上详细的实例代码。如能在实战中融会贯通、灵活使用,必将使代码更为精炼、高效,同时也会极大提升代码B格,使之看上去更老练,读起来更优雅。 1. for - else 什么?不是 if 和 else 才
数据库优化 - SQL优化
前面一篇文章从实例的角度进行数据库优化,通过配置一些参数让数据库性能达到最优。但是一些“不好”的SQL也会导致数据库查询变慢,影响业务流程。本文从SQL角度进行数据库优化,提升SQL运行效率。 判断问题SQL 判断SQL是否有问题时可以通过两个表象进行判断: 系统级别表象 CPU消耗严重 IO等待严重 页面响应时间过长
2019年11月中国大陆编程语言排行榜
2019年11月2日,我统计了某招聘网站,获得有效程序员招聘数据9万条。针对招聘信息,提取编程语言关键字,并统计如下: 编程语言比例 rank pl_ percentage 1 java 33.62% 2 c/c++ 16.42% 3 c_sharp 12.82% 4 javascript 12.31% 5 python 7.93% 6 go 7.25% 7
通俗易懂地给女朋友讲:线程池的内部原理
餐厅的约会 餐盘在灯光的照耀下格外晶莹洁白,女朋友拿起红酒杯轻轻地抿了一小口,对我说:“经常听你说线程池,到底线程池到底是个什么原理?”我楞了一下,心里想女朋友今天是怎么了,怎么突然问出这么专业的问题,但做为一个专业人士在女朋友面前也不能露怯啊,想了一下便说:“我先给你讲讲我前同事老王的故事吧!” 大龄程序员老王 老王是一个已经北漂十多年的程序员,岁数大了,加班加不动了,升迁也无望,于是拿着手里
经典算法(5)杨辉三角
写在前面: 我是 扬帆向海,这个昵称来源于我的名字以及女朋友的名字。我热爱技术、热爱开源、热爱编程。技术是开源的、知识是共享的。 这博客是对自己学习的一点点总结及记录,如果您对 Java、算法 感兴趣,可以关注我的动态,我们一起学习。 用知识改变命运,让我们的家人过上更好的生活。 目录一、杨辉三角的介绍二、杨辉三角的算法思想三、代码实现1.第一种写法2.第二种写法 一、杨辉三角的介绍 百度
腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹?
昨天,有网友私信我,说去阿里面试,彻底的被打击到了。问了为什么网上大量使用ThreadLocal的源码都会加上private static?他被难住了,因为他从来都没有考虑过这个问题。无独有偶,今天笔者又发现有网友吐槽了一道腾讯的面试题,我们一起来看看。 腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹? 在互联网职场论坛,一名程序员发帖求助到。二面腾讯,其中一个算法题:64匹
面试官:你连RESTful都不知道我怎么敢要你?
面试官:了解RESTful吗? 我:听说过。 面试官:那什么是RESTful? 我:就是用起来很规范,挺好的 面试官:是RESTful挺好的,还是自我感觉挺好的 我:都挺好的。 面试官:… 把门关上。 我:… 要干嘛?先关上再说。 面试官:我说出去把门关上。 我:what ?,夺门而去 文章目录01 前言02 RESTful的来源03 RESTful6大原则1. C-S架构2. 无状态3.统一的接
为啥国人偏爱Mybatis,而老外喜欢Hibernate/JPA呢?
关于SQL和ORM的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行了一番讨论,感触还是有一些,于是就有了今天这篇文。 声明:本文不会下关于Mybatis和JPA两个持久层框架哪个更好这样的结论。只是摆事实,讲道理,所以,请各位看官勿喷。 一、事件起因 关于Mybatis和JPA孰优孰劣的问题,争论已经很多年了。一直也没有结论,毕竟每个人的喜好和习惯是大不相同的。我也看
SQL-小白最佳入门sql查询一
一 说明 如果是初学者,建议去网上寻找安装Mysql的文章安装,以及使用navicat连接数据库,以后的示例基本是使用mysql数据库管理系统; 二 准备前提 需要建立一张学生表,列分别是id,名称,年龄,学生信息;本示例中文章篇幅原因SQL注释略; 建表语句: CREATE TABLE `student` ( `id` int(11) NOT NULL AUTO_INCREMENT, `
项目中的if else太多了,该怎么重构?
介绍 最近跟着公司的大佬开发了一款IM系统,类似QQ和微信哈,就是聊天软件。我们有一部分业务逻辑是这样的 if (msgType = "文本") { // dosomething } else if(msgType = "图片") { // doshomething } else if(msgType = "视频") { // doshomething } else { // dosho
【图解经典算法题】如何用一行代码解决约瑟夫环问题
约瑟夫环问题算是很经典的题了,估计大家都听说过,然后我就在一次笔试中遇到了,下面我就用 3 种方法来详细讲解一下这道题,最后一种方法学了之后保证让你可以让你装逼。 问题描述:编号为 1-N 的 N 个士兵围坐在一起形成一个圆圈,从编号为 1 的士兵开始依次报数(1,2,3…这样依次报),数到 m 的 士兵会被杀死出列,之后的士兵再从 1 开始报数。直到最后剩下一士兵,求这个士兵的编号。 1、方
致 Python 初学者
文章目录1. 前言2. 明确学习目标,不急于求成,不好高骛远3. 在开始学习 Python 之前,你需要做一些准备2.1 Python 的各种发行版2.2 安装 Python2.3 选择一款趁手的开发工具3. 习惯使用IDLE,这是学习python最好的方式4. 严格遵从编码规范5. 代码的运行、调试5. 模块管理5.1 同时安装了py2/py35.2 使用Anaconda,或者通过IDE来安装模
“狗屁不通文章生成器”登顶GitHub热榜,分分钟写出万字形式主义大作
一、垃圾文字生成器介绍 最近在浏览GitHub的时候,发现了这样一个骨骼清奇的雷人项目,而且热度还特别高。 项目中文名:狗屁不通文章生成器 项目英文名:BullshitGenerator 根据作者的介绍,他是偶尔需要一些中文文字用于GUI开发时测试文本渲染,因此开发了这个废话生成器。但由于生成的废话实在是太过富于哲理,所以最近已经被小伙伴们给玩坏了。 他的文风可能是这样的: 你发现,
程序员:我终于知道post和get的区别
IT界知名的程序员曾说:对于那些月薪三万以下,自称IT工程师的码农们,其实我们从来没有把他们归为我们IT工程师的队伍。他们虽然总是以IT工程师自居,但只是他们一厢情愿罢了。 此话一出,不知激起了多少(码农)程序员的愤怒,却又无可奈何,于是码农问程序员。 码农:你知道get和post请求到底有什么区别? 程序员:你看这篇就知道了。 码农:你月薪三万了? 程序员:嗯。 码农:你是怎么做到的? 程序员:
《程序人生》系列-这个程序员只用了20行代码就拿了冠军
你知道的越多,你不知道的越多 点赞再看,养成习惯GitHub上已经开源https://github.com/JavaFamily,有一线大厂面试点脑图,欢迎Star和完善 前言 这一期不算《吊打面试官》系列的,所有没前言我直接开始。 絮叨 本来应该是没有这期的,看过我上期的小伙伴应该是知道的嘛,双十一比较忙嘛,要值班又要去帮忙拍摄年会的视频素材,还得搞个程序员一天的Vlog,还要写BU
加快推动区块链技术和产业创新发展,2019可信区块链峰会在京召开
      11月8日,由中国信息通信研究院、中国通信标准化协会、中国互联网协会、可信区块链推进计划联合主办,科技行者协办的2019可信区块链峰会将在北京悠唐皇冠假日酒店开幕。   区块链技术被认为是继蒸汽机、电力、互联网之后,下一代颠覆性的核心技术。如果说蒸汽机释放了人类的生产力,电力解决了人类基本的生活需求,互联网彻底改变了信息传递的方式,区块链作为构造信任的技术有重要的价值。   1
程序员把地府后台管理系统做出来了,还有3.0版本!12月7号最新消息:已在开发中有github地址
第一幕:缘起 听说阎王爷要做个生死簿后台管理系统,我们派去了一个程序员…… 996程序员做的梦: 第一场:团队招募 为了应对地府管理危机,阎王打算找“人”开发一套地府后台管理系统,于是就在地府总经办群中发了项目需求。 话说还是中国电信的信号好,地府都是满格,哈哈!!! 经常会有外行朋友问:看某网站做的不错,功能也简单,你帮忙做一下? 而这次,面对这样的需求,这个程序员
网易云6亿用户音乐推荐算法
网易云音乐是音乐爱好者的集聚地,云音乐推荐系统致力于通过 AI 算法的落地,实现用户千人千面的个性化推荐,为用户带来不一样的听歌体验。 本次分享重点介绍 AI 算法在音乐推荐中的应用实践,以及在算法落地过程中遇到的挑战和解决方案。 将从如下两个部分展开: AI 算法在音乐推荐中的应用 音乐场景下的 AI 思考 从 2013 年 4 月正式上线至今,网易云音乐平台持续提供着:乐屏社区、UGC
【技巧总结】位运算装逼指南
位算法的效率有多快我就不说,不信你可以去用 10 亿个数据模拟一下,今天给大家讲一讲位运算的一些经典例子。不过,最重要的不是看懂了这些例子就好,而是要在以后多去运用位运算这些技巧,当然,采用位运算,也是可以装逼的,不信,你往下看。我会从最简单的讲起,一道比一道难度递增,不过居然是讲技巧,那么也不会太难,相信你分分钟看懂。 判断奇偶数 判断一个数是基于还是偶数,相信很多人都做过,一般的做法的代码如下
日均350000亿接入量,腾讯TubeMQ性能超过Kafka
整理 | 夕颜出品 | AI科技大本营(ID:rgznai100) 【导读】近日,腾讯开源动作不断,相继开源了分布式消息中间件TubeMQ,基于最主流的 OpenJDK8开发的
8年经验面试官详解 Java 面试秘诀
    作者 | 胡书敏 责编 | 刘静 出品 | CSDN(ID:CSDNnews) 本人目前在一家知名外企担任架构师,而且最近八年来,在多家外企和互联网公司担任Java技术面试官,前后累计面试了有两三百位候选人。在本文里,就将结合本人的面试经验,针对Java初学者、Java初级开发和Java开发,给出若干准备简历和准备面试的建议。   Java程序员准备和投递简历的实
面试官如何考察你的思维方式?
1.两种思维方式在求职面试中,经常会考察这种问题:北京有多少量特斯拉汽车? 某胡同口的煎饼摊一年能卖出多少个煎饼? 深圳有多少个产品经理? 一辆公交车里能装下多少个乒乓球? 一
so easy! 10行代码写个"狗屁不通"文章生成器
前几天,GitHub 有个开源项目特别火,只要输入标题就可以生成一篇长长的文章。背后实现代码一定很复杂吧,里面一定有很多高深莫测的机器学习等复杂算法不过,当我看了源代码之后这程序不到50
知乎高赞:中国有什么拿得出手的开源软件产品?(整理自本人原创回答)
知乎高赞:中国有什么拿得出手的开源软件产品? 在知乎上,有个问题问“中国有什么拿得出手的开源软件产品(在 GitHub 等社区受欢迎度较好的)?” 事实上,还不少呢~ 本人于2019.7.6进行了较为全面的 回答 - Bravo Yeung,获得该问题下回答中得最高赞(236赞和1枚专业勋章),对这些受欢迎的 Github 开源项目分类整理如下: 分布式计算、云平台相关工具类 1.SkyWalk
MySQL数据库总结
文章目录一、数据库简介二、MySQL数据类型(5.5版本)三、Sql语句(1)Sql语句简介(2)数据定义语言DDLcreate,alter,drop(3)数据操纵语言DMLupdate,insert,delete(4)数据控制语言DCLgrant,revoke(5)数据查询语言DQLselect(6)分组查询与分页查询group by,limit四、完整性约束(单表)五、多表查询六、MySQL数
记一次腾讯面试:进程之间究竟有哪些通信方式?如何通信? ---- 告别死记硬背
有一次面试的时候,被问到进程之间有哪些通信方式,不过由于之前没深入思考且整理过,说的并不好。想必大家也都知道进程有哪些通信方式,可是我猜很多人都是靠着”背“来记忆的,所以今天的这篇文章,讲给大家详细着讲解他们是如何通信的,让大家尽量能够理解他们之间的区别、优缺点等,这样的话,以后面试官让你举例子,你也能够顺手拈来。 1、管道 我们来看一条 Linux 的语句 netstat -tulnp | gr...
20行Python代码爬取王者荣耀全英雄皮肤
引言 王者荣耀大家都玩过吧,没玩过的也应该听说过,作为时下最火的手机MOBA游戏,咳咳,好像跑题了。我们今天的重点是爬取王者荣耀所有英雄的所有皮肤,而且仅仅使用20行Python代码即可完成。 准备工作 爬取皮肤本身并不难,难点在于分析,我们首先得得到皮肤图片的url地址,话不多说,我们马上来到王者荣耀的官网: 我们点击英雄资料,然后随意地选择一位英雄,接着F12打开调试台,找到英雄原皮肤的图片
走进高并发(二)Java并行程序基础
一、进程和线程 在操作系统这门课程中,对进程的定义是这样的: 进程是计算机中的程序关于某数据集合上的一次运行活动,是系统进行资源分配和调度的基本单位,是操作系统结构的基础。在早期面向进程设计的计算机结构中,进行是程序的基本执行实体;在当代面向线程设计的计算机结构中,进程是线程的容器。 上面的定义很完整,对进程进行了全方面的定义,但是貌似进程是看不见摸不着的一个东西,实际上,我们可以通过查看计算...
相关热词 如何提升c#开发能力 矩阵乘法c# c#调用谷歌浏览器 c# 去空格去转义符 c#用户登录窗体代码 c# 流 c# linux 可视化 c# mvc 返回图片 c# 像素空间 c# 日期 最后一天
立即提问

相似问题

2
使用maven+spring+hibernate开发时,无法自动在数据库中建表?
4
Http servlet中使用hibernate无法添加数据到mysql
1
在集成hibernate之后,springboot再次启动失败(个人怀疑是@EntityScan没扫描的实体类)
0
关于hibernate一个类和多个类有关联关系
2
hibernate初识框架搭建,一直报错
1
Hibernate 读取配置文件出错!!!
1
Spring5 整合Hibernate5 Hibernatetemplate中Find方法过时
2
关于hibernate3的映射问题
2
報錯org.hibernate.AnnotationException: Associated class not found: java.lang.String
5
JPA+Hibernate架構上可以使用HQL嗎?
1
hibernate中执行原生SQL进行插入操作不起作用,sql在数据库中能正常执行
1
Hibernate跳錯 org.hibernate.hql.internal.ast.QuerySyntaxException
1
log4j 输出文件不打印hibernate sql语句?
1
maven项目测试hibernate,导了包却还是有找不到sessionfactory类
3
Springboot集成hibernate+HibernateDaoSupport
2
hibernate中怎么使用TOP 1 id 这类函数,不是分页设置!!!
1
springboot 配置hibernate 开始使用的是mysql,都正常,但是换成Oracle后总是创建表。
1
使用mybatis,javabean类添加一个其他bean类,导致映射失败,有没有像hibernate的@Transient和mybatis-plus的@TableField(exist = false)一样的注解在一定时候忽略这个字段?
0
springboot2.1.4 + jpa + hibernate 使用aop注解形式实现多数据源管理 可能懒加载出现问题求大神解答
2
请问为什么创建hibernate.cfg.xml文件,最后一步点击finish没有反应?