私のプロジェクトでは、テストを行うために、DbUnit 2.4.8 と org.unitils 3.3がopenjpa 1.2.2で使用されています。
テストを実行したいとき、1つのテーブルの作成に問題があります。これは私が受け取るエラーです:
org.unitils.core.UnitilsException: Error inserting test data from DbUnit dataset for method public void be.fed.minfin.adminctx.backend.dao.impl.HistMouvementDAOTest.testMoveStepAndPhaseForward()
at org.unitils.dbunit.DbUnitModule.insertDataSet(DbUnitModule.java:156)
at
......................
Caused by: org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is <openjpa-1.2.2-r422266:898935 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: *unexpected token: ORDER {stmnt 17691874 CREATE TABLE CatDocumentTypeModeleLabelLevel (Langue VARCHAR(255) NOT NULL, SIDCatDocumentTypeModeleLevel INTEGER NOT NULL, Label VARCHAR(255), Level INTEGER, Order INTEGER, Phase INTEGER, Visible BIT, PRIMARY KEY (Langue, SIDCatDocumentTypeModeleLevel))} [code=-5581, state=42581]*
at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:375)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:377)
実際には、"order" という名前の列 (エンティティ "Niveau" で表される) で作成されたテーブルがあります。そして、私はこれを使用する必要があります (このテーブルを作成したのは私ではありません)。
persistence-test.xml では、プロパティを使用します。openjpa.jdbc.SynchronizeMappings に値 buildSchema(ForeignKeys=true) を指定して、エンティティとのマッピングを自動的に作成します。
また、テストで使用されるすべてのクラス (エンティティ) も宣言します。
1つのエンティティのみについて、列「注文」の名前を構成して、別の名前に変更したいと思います...そして、他のエンティティについては、その自動マッピングを維持したいと思います(メタデータ用)。
だから私の質問は、どうすればそれを行うことができますか?
これはpersistence-test.xmlです
<?xml version="1.0" encoding="UTF-8"?>
<!-- Persistence deployment descriptor for dev profile -->
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<class>be.fed.minfin.adminctx.backend.model.MigrationProject</class>
<class>be.fed.minfin.adminctx.backend.model.MigrationProperty</class>
<class>be.fed.minfin.adminctx.backend.model.MigrationPropertyMappingValue</class>
<class>be.fed.minfin.adminctx.backend.model.MigrationSearchProperty</class>
<class>be.fed.minfin.adminctx.backend.model.ElementTravail</class>
<class>be.fed.minfin.adminctx.backend.model.Litige</class>
<class>be.fed.minfin.adminctx.backend.model.TraitementAdmin</class>
<class>be.fed.minfin.adminctx.backend.model.Cassation</class>
<class>be.fed.minfin.adminctx.backend.model.ExecutionJudiciaire</class>
<class>be.fed.minfin.adminctx.backend.model.LigneObjet</class>
<class>be.fed.minfin.adminctx.backend.model.Contribuable</class>
<class>be.fed.minfin.adminctx.backend.model.ProcedureJudiciaire</class>
<class>be.fed.minfin.adminctx.backend.model.TPI</class>
<class>be.fed.minfin.adminctx.backend.model.ArbitrageJustice</class>
<class>be.fed.minfin.adminctx.backend.model.IntervenantsAdmin</class>
<class>be.fed.minfin.adminctx.backend.model.Flux</class>
<class>be.fed.minfin.adminctx.backend.model.Article</class>
<class>be.fed.minfin.adminctx.backend.model.LigneAgenda</class>
<class>be.fed.minfin.adminctx.backend.model.Appel</class>
<class>be.fed.minfin.adminctx.backend.model.Assistance</class>
<class>be.fed.minfin.adminctx.backend.model.IntervenantsTaxation</class>
<class>be.fed.minfin.adminctx.backend.model.Reclamation</class>
<class>be.fed.minfin.adminctx.backend.model.Resume</class>
<class>be.fed.minfin.adminctx.backend.model.DemandeAvocatTPI</class>
<class>be.fed.minfin.adminctx.backend.model.DemandeAvocatAppel</class>
<class>be.fed.minfin.adminctx.backend.model.ArretCassation</class>
<class>be.fed.minfin.adminctx.backend.model.IntervenantsTPI</class>
<class>be.fed.minfin.adminctx.backend.model.IntervenantsAssistance</class>
<class>be.fed.minfin.adminctx.backend.model.IntervenantsAppel</class>
<class>be.fed.minfin.adminctx.backend.model.IntervenantsExecution</class>
<class>be.fed.minfin.adminctx.backend.model.Mandataire</class>
<class>be.fed.minfin.adminctx.backend.model.IntervenantsArbitrage</class>
<class>be.fed.minfin.adminctx.backend.model.ArretArbitrageJustice</class>
<class>be.fed.minfin.adminctx.backend.model.ArretAppel</class>
<class>be.fed.minfin.adminctx.backend.model.IntervenantsResume</class>
<class>be.fed.minfin.adminctx.backend.model.RequeteAppel</class>
<class>be.fed.minfin.adminctx.backend.model.RequeteCassation</class>
<class>be.fed.minfin.adminctx.backend.model.Avocat</class>
<class>be.fed.minfin.adminctx.backend.model.JugementTPI</class>
<class>be.fed.minfin.adminctx.backend.model.IntervenantsJud</class>
<class>be.fed.minfin.adminctx.backend.model.Grief</class>
<class>be.fed.minfin.adminctx.backend.model.LitigeISI</class>
<class>be.fed.minfin.adminctx.backend.model.RequeteTPI</class>
<class>be.fed.minfin.adminctx.backend.model.IntervenantsCassation</class>
<class>be.fed.minfin.adminctx.backend.model.HistMouvement</class>
<class>be.fed.minfin.adminctx.backend.model.SIPTaxateurKey</class>
<class>be.fed.minfin.adminctx.backend.model.SIPTaxateur</class>
<class>be.fed.minfin.adminctx.backend.model.ServiceContentieux</class>
<class>be.fed.minfin.adminctx.backend.model.AvocatEB</class>
<class>be.fed.minfin.adminctx.backend.model.AvocatEBCassation</class>
<class>be.fed.minfin.adminctx.backend.model.CoursAppel</class>
<class>be.fed.minfin.adminctx.backend.model.Tribunal</class>
<class>be.fed.minfin.adminctx.backend.model.Niveau</class>
<class>be.fed.minfin.adminctx.backend.model.LitigationReport</class>
<class>be.fed.minfin.adminctx.backend.model.LitigationReportElement</class>
<class>be.fed.minfin.adminctx.backend.model.LitigationReportElementType</class>
<class>be.fed.minfin.adminctx.backend.model.views.ElementTravailIntervenantsView</class>
<properties>
<property name="openjpa.Log" value="DefaultLevel=INFO" />
<property name="openjpa.Log" value="SQL=TRACE" />
<property name="openjpa.ConnectionDriverName" value="org.hsqldb.jdbcDriver" />
<property name="openjpa.ConnectionURL" value="jdbc:hsqldb:mem:adminctxtest" />
<property name="openjpa.jdbc.DBDictionary" value="org.apache.openjpa.jdbc.sql.HSQLDictionary"/>
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
<property name="hibernate.dialect"
value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
</properties>
</persistence-unit>
</persistence>
これは関係エンティティ (Niveau.java) です。
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
@Entity
@IdClass (NiveauPK.class)
@Table(name="CatDocumentTypeModeleLabelLevel")
@NamedQueries({
@NamedQuery(name="SearchInAllLanguages",
query="SELECT n from Niveau n " +
"WHERE n.sidNiveau = ?1 ")})
public class Niveau implements ModelObject<Integer> , Serializable
{
/**
*
*/
private static final long serialVersionUID = 4407369231768353626L;
@Column(name = "Level")
protected Integer level;
@Column(name = "Label")
protected String label;
@Id
//@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name = "SIDCatDocumentTypeModeleLevel")
protected Integer sidNiveau;
@Id
@Column(name ="Langue")
protected String langue;
@Column(name = "Order")
protected Integer order;
/**
* @Catalog: CatPhase
*/
@Column(name = "Phase")
protected Integer phase;
/**
* @Catalog: CatBoolean
*/
@Column(name = "Visible")
protected Boolean visible;
@Override
public Integer getId() {
// TODO Auto-generated method stub
return sidNiveau;
}
@Override
public void setId(Integer id) {
this.setId(sidNiveau);
}
public Integer getLevel() {
return level;
}
public void setLevel(Integer level) {
this.level = level;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getLangue() {
return langue;
}
public void setLangue(String langue) {
this.langue = langue;
}
public Integer getOrder() {
return order;
}
public void setOrder(Integer order) {
this.order = order;
}
public Integer getPhase() {
return phase;
}
public void setPhase(Integer phase) {
this.phase = phase;
}
public Boolean getVisible() {
return visible;
}
public void setVisible(Boolean visible) {
this.visible = visible;
}
public Integer getSidNiveau() {
return sidNiveau;
}
public void setSidNiveau(Integer sidNiveau) {
this.sidNiveau = sidNiveau;
}
......
そして、これがDbunitがテーブルを作成する方法です
82 test INFO [main] openjpa.jdbc.JDBC - Using dictionary class "org.apache.openjpa.jdbc.sql.HSQLDictionary".
2250 test TRACE [main] openjpa.jdbc.SQL - <t 13737183, conn 26350769> executing prepstmnt 3534544 SELECT SEQUENCE_SCHEMA, SEQUENCE_NAME FROM INFORMATION_SCHEMA.SYSTEM_SEQUENCES
2250 test TRACE [main] openjpa.jdbc.SQL - <t 13737183, conn 26350769> [0 ms] spent
2254 test TRACE [main] openjpa.jdbc.SQL - <t 13737183, conn 26350769> executing stmnt 1247640 CREATE TABLE Appel (SIDAppel INTEGER NOT NULL, ArretCourant INTEGER, AudienceIntroDate TIMESTAMP, AudienceIntroResultat INTEGER, CassationArretInterlocutoire BIT, DateAcquiescementPA TIMESTAMP, DateConsultationPAEB TIMESTAMP, DateEnvoiPremiereCCLEB TIMESTAMP, DateIntroductionEB TIMESTAMP, DateIntroductionPA TIMESTAMP, DateOppositionEB TIMESTAMP, DateOppositionPA TIMESTAMP, DateReceptionRequetePA TIMESTAMP, DateSignificationArretEB TIMESTAMP, DateSignificationArretPA TIMESTAMP, Demande356 BIT, DirectionRegionale BIT, ExecArretType INTEGER, ExpirationDelaiCassation TIMESTAMP, ExpirationDelaiCassationEffect TIMESTAMP, IncidentEB BIT, IncidentPA BIT, InvitationTaxateur BIT, LitigePlaide BIT, NomCour INTEGER, NomCour2 INTEGER, NomCourRenvoi1 INTEGER, NomCourRenvoi2 INTEGER, ReAttributionMiseEnEtatAppel BIT, Requete356Signifiee BIT, RetourMiseEnEtatAppel BIT, SuiviArretType INTEGER, SIDLitige INTEGER, PRIMARY KEY (SIDAppel))
2254 test TRACE [main] openjpa.jdbc.SQL - <t 13737183, conn 26350769> [0 ms] spent
2255 test TRACE [main] openjpa.jdbc.SQL - <t 13737183, conn 26350769> executing stmnt 14662467 CREATE TABLE ArbitrageJustice (SIDArbitrageJustice INTEGER NOT NULL, ArretCourant INTEGER, Avocat2Nom INTEGER, Avocat2Reference VARCHAR(255), AvocatNom INTEGER, AvocatReference VARCHAR(255), DateNotificationGreffe TIMESTAMP, DateNotificationNotePA TIMESTAMP, LitigePlaide BIT, TypeCour INTEGER, SIDLitige INTEGER, PRIMARY KEY (SIDArbitrageJustice))
2255 test TRACE [main] openjpa.jdbc.SQL - <t 13737183, conn 26350769> [0 ms] spent
2255 test TRACE [main] openjpa.jdbc.SQL - <t 13737183, conn 26350769> executing stmnt 28301772 CREATE TABLE ArretAppel (SIDArretAppel INTEGER NOT NULL, Arret1Date TIMESTAMP, Arret1Resume INTEGER, Arret1ResumeEnCours BIT, Arret1Type1 INTEGER, Arret1Type2 INTEGER, Arret1Type3 INTEGER, Arret2Date TIMESTAMP, Arret2Resume INTEGER, Arret2ResumeEnCours BIT, Arret2Type1 INTEGER, Arret2Type2 INTEGER, Arret2Type3 INTEGER, Arret3Date TIMESTAMP, Arret3Resume INTEGER, Arret3ResumeEnCours BIT, Arret3Type1 INTEGER, Arret3Type2 INTEGER, Arret3Type3 INTEGER, Arret4Date TIMESTAMP, Arret4Resume INTEGER, Arret4ResumeEnCours BIT, Arret4Type1 INTEGER, Arret4Type2 INTEGER, Arret4Type3 INTEGER, Arret5Date TIMESTAMP, Arret5Resume INTEGER, Arret5ResumeEnCours BIT, Arret5Type1 INTEGER, Arret5Type2 INTEGER, Arret5Type3 INTEGER, SIDAppel INTEGER, PRIMARY KEY (SIDArretAppel))
2256 test TRACE [main] openjpa.jdbc.SQL - <t 13737183, conn 26350769> [1 ms] spent
2256 test TRACE [main] openjpa.jdbc.SQL - <t 13737183, conn 26350769> executing stmnt 9826960 CREATE TABLE ArretArbitrageJustice (SIDArretArbitrageJustice INTEGER NOT NULL, Arret1Cour INTEGER, Arret1Date TIMESTAMP, Arret1Resume INTEGER, Arret1ResumeEnCours BIT, Arret1Type INTEGER, Arret2Cour INTEGER, Arret2Date TIMESTAMP, Arret2Resume INTEGER, Arret2ResumeEnCours BIT, Arret2Type INTEGER, SIDArbitrageJustice INTEGER, PRIMARY KEY (SIDArretArbitrageJustice))
2256 test TRACE [main] openjpa.jdbc.SQL - <t 13737183, conn 26350769> [0 ms] spent
2256 test TRACE [main] openjpa.jdbc.SQL - <t 13737183, conn 26350769> executing stmnt 25250173 CREATE TABLE ArretCassation (SIDArretCassation INTEGER NOT NULL, Arret1Date TIMESTAMP, Arret1Resume INTEGER, Arret1ResumeEnCours BIT, Arret1Type1 INTEGER, Arret1Type2 INTEGER, Arret1Type3 INTEGER, Arret2Date TIMESTAMP, Arret2Resume INTEGER, Arret2ResumeEnCours BIT, Arret2Type1 INTEGER, Arret2Type2 INTEGER, Arret2Type3 INTEGER, Arret3Date TIMESTAMP, Arret3Resume INTEGER, Arret3ResumeEnCours BIT, Arret3Type1 INTEGER, Arret3Type2 INTEGER, Arret3Type3 INTEGER, SIDCassation INTEGER, PRIMARY KEY (SIDArretCassation))
2257 test TRACE [main] openjpa.jdbc.SQL - <t 13737183, conn 26350769> [1 ms] spent
2257 test TRACE [main] openjpa.jdbc.SQL - <t 13737183, conn 26350769> executing stmnt 11154712 CREATE TABLE Article (SIDArticle INTEGER NOT NULL, Art747par1 BIT, Art747par2DateNotification TIMESTAMP, Art747par2EB BIT, Art747par2PA BIT, Art748par2DateNotification TIMESTAMP, Art748par2EB BIT, Art748par2PA BIT, Art750par1 BIT, Art750par2DateNotification TIMESTAMP, Art750par2EB BIT, Art750par2PA BIT, Art751DateNotification TIMESTAMP, Art751EB BIT, Art751PA BIT, SIDLitige INTEGER, PRIMARY KEY (SIDArticle))
2257 test TRACE [main] openjpa.jdbc.SQL - <t 13737183, conn 26350769> [0 ms] spent
2257 test TRACE [main] openjpa.jdbc.SQL - <t 13737183, conn 26350769> executing stmnt 7272378 CREATE TABLE Assistance (SIDAssistance INTEGER NOT NULL, AppelAssistanceDemande BIT, AssistanceEnCours BIT, AssistanceTaxateur BIT, CommentaireSuivant VARCHAR(255), DemandeAssistanceAC BIT, DemandeModification BIT, ExecutionCommentaire VARCHAR(255), ExecutionType INTEGER, ReponseAC BIT, TPIAssistanceDemande BIT, SIDLitige INTEGER, PRIMARY KEY (SIDAssistance))
2258 test TRACE [main] openjpa.jdbc.SQL - <t 13737183, conn 26350769> [1 ms] spent
2258 test TRACE [main] openjpa.jdbc.SQL - <t 13737183, conn 26350769> executing stmnt 26757789 CREATE TABLE Avocat (SIDAvocat INTEGER NOT NULL, Adresse1 VARCHAR(255), Adresse1AvocatEpoux VARCHAR(255), Adresse2 VARCHAR(255), Adresse2AvocatEpoux VARCHAR(255), Adresse3 VARCHAR(255), Adresse3AvocatEpoux VARCHAR(255), AdressePays VARCHAR(255), AdressePaysAvocatEpoux VARCHAR(255), DateDeces TIMESTAMP, DateDecesEpoux TIMESTAMP, DateValidation TIMESTAMP, DateValidationEpoux TIMESTAMP, Email VARCHAR(255), EmailAvocatEpoux VARCHAR(255), GSM VARCHAR(255), GSMAvocatEpoux VARCHAR(255), Nom VARCHAR(255), NomAvocatEpoux VARCHAR(255), NumNational VARCHAR(255), NumNationalEpoux VARCHAR(255), PersIdf VARCHAR(255), PersIdfEpoux VARCHAR(255), Prenom VARCHAR(255), PrenomAvocatEpoux VARCHAR(255), ReferenceCourrier VARCHAR(255), ReferenceCourrierAvocatEpoux VARCHAR(255), StatutJuridique INTEGER, StatutJuridiqueEpoux INTEGER, StatutValidation BIT, StatutValidationEpoux BIT, Telephone VARCHAR(255), TelephoneAvocatEpoux VARCHAR(255), TvaCodePays VARCHAR(255), TvaCodePaysEpoux VARCHAR(255), TvaNumero VARCHAR(255), TvaNumeroEpoux VARCHAR(255), UpersIdf VARCHAR(255), UpersIdfEpoux VARCHAR(255), SIDContribuable INTEGER, PRIMARY KEY (SIDAvocat))
2258 test TRACE [main] openjpa.jdbc.SQL - <t 13737183, conn 26350769> [0 ms] spent
2259 test TRACE [main] openjpa.jdbc.SQL - <t 13737183, conn 26350769> executing stmnt 32316862 CREATE TABLE Cassation (SIDCassation INTEGER NOT NULL, ArretCourant INTEGER, AvocatNom INTEGER, AvocatReference VARCHAR(255), DateIntroductionEB TIMESTAMP, DateIntroductionPA TIMESTAMP, DateReceptionRequetePA TIMESTAMP, DateSignificationEB TIMESTAMP, DateSignificationPA TIMESTAMP, DateSignificationRequeteEB TIMESTAMP, DateSignificationRequetePA TIMESTAMP, DirectionRegionale BIT, ExecArretType INTEGER, SuiviArretType INTEGER, SIDLitige INTEGER, PRIMARY KEY (SIDCassation))
2259 test TRACE [main] openjpa.jdbc.SQL - <t 13737183, conn 26350769> [0 ms] spent
2259 test TRACE [main] openjpa.jdbc.SQL - <t 13737183, conn 26350769> executing stmnt 17691874 CREATE TABLE CatDocumentTypeModeleLabelLevel (Langue VARCHAR(255) NOT NULL, SIDCatDocumentTypeModeleLevel INTEGER NOT NULL, Label VARCHAR(255), Level INTEGER, Order INTEGER, Phase INTEGER, Visible BIT, PRIMARY KEY (Langue, SIDCatDocumentTypeModeleLevel))
2275 test TRACE [main] openjpa.jdbc.SQL - <t 13737183, conn 26350769> [16 ms] spent