如题。我的hibernate配置如下:<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns: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-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<!-- data source -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName">
<value>org.postgresql.Driver</value>
</property>
<property name="url">
<value>jdbc:postgresql://127.0.0.1:5432/db</value>
</property>
<property name="username">
<value>admin</value>
</property>
<property name="password">
<value>admin</value>
</property>
<property name="maxActive">
<value>40</value>
</property>
<property name="maxIdle">
<value>15</value>
</property>
<property name="initialSize">
<value>10</value>
</property>
<property name="maxWait">
<value>120000</value>
</property>
<property name="defaultAutoCommit">
<value>true</value>
</property>
<property name="removeAbandoned">
<value>true</value>
</property>
<property name="removeAbandonedTimeout">
<value>500</value>
</property>
<property name="logAbandoned">
<value>true</value>
</property>
<property name="validationQuery">
<value>select 1</value>
</property>
<property name="testOnBorrow">
<value>true</value>
</property>
</bean>
<!-- session factory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="mappingLocations" value="classpath*:com/*.hbm.xml" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="connection.useUnicode">true</prop>
<prop key="connection.characterEncoding">UTF-8</prop>
</props>
</property>
</bean> <bean id="hibernateTransactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean> <bean id="hibernateManager"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
abstract="true">
<property name="transactionManager">
<ref bean="hibernateTransactionManager"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="search*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="add*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="save*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="update*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="submit*">PROPAGATION_REQUIRED,-Exception</prop>
</props>
</property>
</bean></beans>
此hibernate是集成到项目Spring中的,在dos下ant生成的ddl和java放到eclipse中运行会出现错误:
...
ERROR org.springframework.web.context.ContextLoader - Context initialization failed
...
现在是根据项目需要修改了hbm.xml映射文件的相关字段,想在eclipse中根据hbm.xml来重新映射。请问何解??!!
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<!-- data source -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName">
<value>org.postgresql.Driver</value>
</property>
<property name="url">
<value>jdbc:postgresql://127.0.0.1:5432/db</value>
</property>
<property name="username">
<value>admin</value>
</property>
<property name="password">
<value>admin</value>
</property>
<property name="maxActive">
<value>40</value>
</property>
<property name="maxIdle">
<value>15</value>
</property>
<property name="initialSize">
<value>10</value>
</property>
<property name="maxWait">
<value>120000</value>
</property>
<property name="defaultAutoCommit">
<value>true</value>
</property>
<property name="removeAbandoned">
<value>true</value>
</property>
<property name="removeAbandonedTimeout">
<value>500</value>
</property>
<property name="logAbandoned">
<value>true</value>
</property>
<property name="validationQuery">
<value>select 1</value>
</property>
<property name="testOnBorrow">
<value>true</value>
</property>
</bean>
<!-- session factory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="mappingLocations" value="classpath*:com/*.hbm.xml" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="connection.useUnicode">true</prop>
<prop key="connection.characterEncoding">UTF-8</prop>
</props>
</property>
</bean> <bean id="hibernateTransactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean> <bean id="hibernateManager"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
abstract="true">
<property name="transactionManager">
<ref bean="hibernateTransactionManager"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="search*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="add*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="save*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="update*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="submit*">PROPAGATION_REQUIRED,-Exception</prop>
</props>
</property>
</bean></beans>
此hibernate是集成到项目Spring中的,在dos下ant生成的ddl和java放到eclipse中运行会出现错误:
...
ERROR org.springframework.web.context.ContextLoader - Context initialization failed
...
现在是根据项目需要修改了hbm.xml映射文件的相关字段,想在eclipse中根据hbm.xml来重新映射。请问何解??!!
接着
2.myeclipse -->window-->open perspective-->myeclipse Hibernate -->DB Broswer中右键 -->new... -->你的数据库联接信息-->test一下如果是successful那就说明你的联接信息是正确的 finish 会有一个东东在DB Broswer里面,你右键-->open Connection--> 你的库,点开“+”--> dbo -->table-->在要生成pojo类的表上右键(这里你要注意能选多个表,并且如果你的库存在关系图,它会把one to many生成出来)-->Hibernate Reverse .....选你要生成的东西,.hbm.xml pojo类,等等
注意,如果你没有做第一步,那在它弹出来的java src folder中是没东西可选的,这里只要选一个包就OK了,就直接finish就可以了,下一步里面的东西我也没研究
好了,生成的代码已经在你选中的包里面了,你进去改一下包名再copy到你要的工程中就OK了,我个人不建议在你的工程上直接加上Hibernate那些乱七八糟的东西,所以让你新建了一个test工程,好了,哥们给分吧,我敲了这么多,还得自己做一便,你怎么也得给分吧,别用2分打发叫花子,我可是记得你名字呢
你说的是在myeclipse中根据数据库表来自动生成hbm.xml和pojo。但是我要问的是 在eclipse中根据已有的hbm.xml映射文件来重新映射生成ddl和java源码啊!!!