java—为什么我在测试启动时只将类Map到表,却收到关于更改表失败的消息?

3vpjnl9f  于 2021-07-07  发布在  Java
关注(0)|答案(0)|浏览(133)

在测试开始时,我将许多表从oracledbMap到java类。刚才我只运行了一个测试查询,它运行正常(谢谢你!)
我打开了这些消息,在上下文创建和表Map阶段,我不仅看到了许多成功的表发现,而且最终看到了一些消息,例如:

TST-[2020/12/02 23:58:53.715] hbm2ddl.SchemaUpdate HHH000388: Unsuccessful: alter table CIS_LOKAL_ROLE_AAA add KOD_LOKAL_ROLA_AAA varchar2(10 char) not null
TST-[2020/12/02 23:58:53.715] hbm2ddl.SchemaUpdate ORA-01758: table must be empty to add mandatory (NOT NULL) column

TST-[2020/12/02 23:58:53.881] hbm2ddl.SchemaUpdate HHH000388: Unsuccessful: alter table P01_OPRAVNENI add constraint FK_c0cufehvbvpf9y3dh0fcjrhak foreign key (ID_OBJEKTU) references R01_RIZENI
TST-[2020/12/02 23:58:53.881] hbm2ddl.SchemaUpdate ORA-02298: cannot validate (SPR.FK_C0CUFEHVBVPF9Y3DH0FCJRHAK) - parent keys not found

为什么hibernate要在Map时更改表?
请注意,这里也有关于类似消息的问题,但是它们涉及到表确实要被修改和失败的情况。虽然我不想修改它们,但唯一的查询是关于计数查询的,这是成功的,并且是在我正在写的问题之后出现的。
测试类别:

@Test//(enabled = false)
@ContextConfiguration(locations={ "classpath:beans_sets/UhradyForIns.xml"/* , "classpath:beans_sets/mvc-config.xml"*/})
@TransactionConfiguration(transactionManager="transactionManager", defaultRollback=false)
@DirtiesContext(classMode= DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class OdeslatJakobyAutomatickyUhraduTest extends TestBaseWithProperties {
    private static final Logger log = LoggerFactory.getLogger(OdeslatJakobyAutomatickyUhraduTest.class);
    @Autowired( required = true )
    U01UhradaBaseJpaDaoForTesting dao;
    @Transactional
    @Test
    public void odeslat(){
        if(dao == null){
            Assert.fail("Null context.");
        }
        dao.setRecordsForSending();
        Reporter.log(new String("Number of uhrady to send = "+dao.countUhradyToSend()));
        //List<U01Uhrada> uhrady = dao.findUhradyProPoslani();
    }
}

public class U01UhradaBaseJpaDaoForTesting {
    @PersistenceContext(unitName="SprUnit")
    protected EntityManager em;

    void setRecordsForSending(){

    }
    long countUhradyToSend(){
        QU01Uhrada uh = QU01Uhrada.u01Uhrada;

        JPAQuery jq = new JPAQuery(em);
        jq.from(uh);
        jq.where(uh.preposlano.eq(U01UhradaPreposlanoEnum.K_PREPOSLANI.asKod()));
        return jq.count();
    }

}

public class TestBaseWithProperties extends AbstractTestNGSpringContextTests {
    {
        //---------------------------------- setting paths
        // absolute path up to main-app
        String mainApp = System.getProperty("user.dir");
        String apv = mainApp.substring(0, mainApp.lastIndexOf("\\"));

        System.setProperty("main.app", mainApp);
        System.setProperty("main.web.webinf", apv + "/main-web/src/main/webapp/WEB-INF");
        System.setProperty("spr.root.dir", mainApp + "/work");

        // -------------------------------------- setting DB
        System.setProperty("database.driver", "oracle.jdbc.driver.OracleDriver");
        System.setProperty("database.url", "jdbc:oracle:thin:@oradb2.companyname.com:1534:INPD12");
        System.setProperty("database.user", "user");
        System.setProperty("database.password", "pass");
    }
}

uhradyforins.xml文件:

<import resource="classpath:META-INF/spring/spr-properties.xml" />

<!--    Database setting -->
<!--<context:property-placeholder location="classpath:beans_sets/database-test.properties"/>-->
<bean id="dataSourceBean"
      class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="${database.driver}"/>
    <property name="url" value="${database.url}"/>
    <property name="username" value="${database.user}"/>
    <property name="password" value="${database.password}"/>
</bean>

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceXmlLocation" value="file:${main.app}/src/test/resources/beans_sets/persistence-spr-test.xml"/>
    <property name="persistenceUnitName" value="SprUnit"/>
    <property name="dataSource" ref="dataSourceBean"/>
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="showSql" value="true"/>
            <property name="generateDdl" value="true" />
        </bean>
    </property>
</bean>

<!-- Automatic Transaction Participation-->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>

<bean id="U01UhradaBaseJpaDaoForTesting" class="amcssz.spr.srv.main.jobs.U01UhradaBaseJpaDaoForTesting"/>

持久性-spr-test.xml

<persistence-unit name="SprUnit" transaction-type="RESOURCE_LOCAL" >
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>jdbc/spr-db</jta-data-source>

    <class>amcssz.spr.srv.main.entity.P01Opravneni</class>
    ....
    <class>amcssz.spr.srv.main.entity.cis.CisLokalRoleAaa</class>

    <exclude-unlisted-classes>false</exclude-unlisted-classes>

    <properties>
<!-- Scan for annotated classes and Hibernate mapping XML files -->
        <property name="hibernate.archive.autodetection" value="class" />
        <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
        <property name="hibernate.format_sql" value="true" />
        <property name="hibernate.max_fetch_depth" value="3" />
        <property name="hibernate.show_sql" value="true" />
    </properties>
</persistence-unit>

问题表的实体:

@Entity
@Table(name="CIS_LOKAL_ROLE_AAA")
public class CisLokalRoleAaa extends AbstractCisEntity implements Serializable {

    private static final long serialVersionUID = -1302716162506083142L;

    @Id  //that column exists in the table
    @Column(name="KOD_LOKAL_ROLA_AAA", unique=true, nullable=false, length=10)
    private String kodLokalRole;

    @Column(name="KOD_PRACOVISTE", length=10)
    private String kodPracoviste;

    public CisLokalRoleAaa() {
    }

    public String getKodLokalRole() {
        return kodLokalRole;
    }

    public void setKodLokalRole(String kodLokalRole) {
        this.kodLokalRole = kodLokalRole;
    }

    public String getKodPracoviste() {
        return kodPracoviste;
    }

    public void setKodPracoviste(String kodPracoviste) {
        this.kodPracoviste = kodPracoviste;
    }
}

@Entity
@Table(name="P01_OPRAVNENI")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "KOD_TYP_OBJEKTU", discriminatorType = DiscriminatorType.STRING)
public class P01Opravneni extends AbstractUpdateable implements Serializable {
    private static final long serialVersionUID = -3009052816433258266L;

    @Id
    @SequenceGenerator(name="P01_OPRAVNENI_IDR02OPRAVNENIRIZENI_GENERATOR", sequenceName="SEQ_P01_OPRAVNENI")
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="P01_OPRAVNENI_IDR02OPRAVNENIRIZENI_GENERATOR")
    @Column(name="ID_P01_OPRAVNENI", unique=true, nullable=false, precision=22)
    private Long idP01Opravneni;

    @Temporal( TemporalType.TIMESTAMP)
    @Column(name="DATINS")
    private Date datins;

    @Column(name="JE_AKTUALNI", nullable=false, precision=1)
    private Boolean jeAktualni;

    @Column(name="VYMAHAC", nullable=false, length=44)
    private String vymahac;

    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="KOD_TYP_OBJEKTU", referencedColumnName="KOD_OBJEKT",nullable=false, insertable=false, updatable=false)
    private CisObjekt cisObjekt;

    @Column(name="KOD_TYP_OBJEKTU",nullable=false, insertable=false,updatable=false)
    private String kodTypObjektu;

    @Column(name="ID_OBJEKTU", nullable=false)
    private Long idObjektu;

    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="KOD_PRACOVISTE", insertable=false, updatable=false)
    private CisPracovisteCssz cisPracovisteCssz;

    @Column(name="KOD_PRACOVISTE", precision=10)
    private String kodPracoviste;

    @Column(name="prevzato_do")
    private Date prevzatoDo; 

    public Long getIdObjektu() {
        return idObjektu;
    }
    public void setIdObjektu(Long idObjektu) {
        this.idObjektu = idObjektu;
    }

    public String getKodTypObjektu() {
        return kodTypObjektu;
    }

    public void setKodTypObjektu(String kodTypObjektu) {
        this.kodTypObjektu = kodTypObjektu;
    }

    public P01Opravneni() {
    }

    public Long getIdP01Opravneni() {
        return idP01Opravneni;
    }
    public void setIdP01Opravneni(Long idP02Opravneni) {
        this.idP01Opravneni = idP02Opravneni;
    }

    public Date getDatins() {
        return datins;
    }
    public void setDatins(Date datins) {
        this.datins = datins;
    }

    public Boolean getJeAktualni() {
        return this.jeAktualni;
    }

    public void setJeAktualni(Boolean jeAktualni) {
        this.jeAktualni = jeAktualni;
    }

    public String getVymahac() {
        return this.vymahac;
    }

    public void setVymahac(String vymahac) {
        this.vymahac = vymahac;
    }

    public CisObjekt getCisObjekt() {
        return this.cisObjekt;
    }

    public void setCisObjekt(CisObjekt cisObjekt) {
        this.cisObjekt = cisObjekt;
    }

    public CisPracovisteCssz getCisPracovisteCssz() {
        return this.cisPracovisteCssz;
    }

    public void setCisPracovisteCssz(CisPracovisteCssz cisPracovisteCssz) {
        this.cisPracovisteCssz = cisPracovisteCssz;
    }

    public String getKodPracoviste() {
        return kodPracoviste;
    }

    public void setKodPracoviste(String kodPracoviste) {
        this.kodPracoviste = kodPracoviste;
    }
    public Date getPrevzatoDo() {
        return prevzatoDo;
    }
    public void setPrevzatoDo(Date prevzatoDo) {
        this.prevzatoDo = prevzatoDo;
    }

}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题