qq_37346184
qq_37346184
2017-10-21 14:06

idea逆向生成的实体类没有和数据库建立对应关系

  • intellij-idea
  • 数据库
  • hibernate

<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">

<context:component-scan base-package="com.Xing"/>

<context:property-placeholder location="classpath:jdbc.properties"/>

<!--配置数据源-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    <property name="driverClass" value="${hibernate.driverClass}"/>
    <property name="jdbcUrl" value="${hibernate.jdbcUrl}"/>
    <property name="user" value="${hibernate.user}"/>
    <property name="password" value="${hibernate.password}"/>
    <!--配置个性化设置-->
    <property name="initialPoolSize" value="1"/>
    <property name="minPoolSize" value="1"/>
    <property name="maxPoolSize" value="15"/>
    <property name="maxConnectionAge" value="28800"/>
    <property name="maxIdleTime" value="21600"/>
</bean>

<!--配置SessionFactory-->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <!--将数据源注入进来-->
    <property name="dataSource" ref="dataSource"/>
    <!--对Hibernate进行配置-->
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</prop>
            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
            <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
            <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
            <prop key="hibernate.hbm2ddl.auto">validate</prop>
            <prop key="hibernate.connection.url">jdbc:mysql://localhost:3306/oa</prop>
            <prop key="hibernate.connection.driver_class">com.mysql.jdbc.Driver</prop>
        </props>
    </property>

    <!--指定@Entity注解扫描的包-->
    <property name="packagesToScan" value="com.Xing.*.entity"/>
</bean>

<!--事务管理器-->
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>

<!--配置事务通知-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
        <!--对方法进行匹配-->
        <!--会进行数据更新的方法,事务传播行为设置为REQUIRED-->
        <tx:method name="add*" propagation="REQUIRED"/>
        <tx:method name="save*" propagation="REQUIRED"/>
        <tx:method name="insert*" propagation="REQUIRED"/>
        <tx:method name="create*" propagation="REQUIRED"/>
        <tx:method name="put*" propagation="REQUIRED"/>
        <tx:method name="update*" propagation="REQUIRED"/>
        <tx:method name="modify*" propagation="REQUIRED"/>
        <tx:method name="change*" propagation="REQUIRED"/>
        <tx:method name="edit*" propagation="REQUIRED"/>
        <tx:method name="delete*" propagation="REQUIRED"/>
        <tx:method name="remove*" propagation="REQUIRED"/>

        <!--不会进行数据更新的方法,事务传播行为设置为REQUIRED-->
        <tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
        <tx:method name="load*" propagation="SUPPORTS" read-only="true"/>
        <tx:method name="list*" propagation="SUPPORTS" read-only="true"/>
        <tx:method name="query*" propagation="SUPPORTS" read-only="true"/>
        <tx:method name="*" propagation="SUPPORTS" read-only="true"/>
    </tx:attributes>
</tx:advice>

<!--配置切面-->
<aop:config>
    <aop:advisor advice-ref="txAdvice" pointcut="execution(* com.Xing.*..service..*.*(..))"/>
</aop:config>


这是ApplicationContext.xml,拜托各位大神了

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答