2011-09-21 3 views
0

Hibernate3 Maven 플러그인을 사용하여 데이터베이스에서 도메인/모델 POJO 생성을 구현 중입니다. DBA의 데이터베이스 업데이트가 개발자가 추가 작업을 시작하기 전에 모델 계층에 자동 매핑되도록하는 것이 이론적 인 이유입니다. 따라서 작동해야하는 방식은 Hibernate CFG가 생성 된 후 POJO가 생성된다는 것입니다. 또한 이전 구현은 hbm.xml 대신 주석을 사용하는 개발자로 구성 되었기 때문에 생성 된 클래스에 주석을 추가해야합니다. 여기에 내가 생성되는 cfg.xml 파일을 볼 수 있습니다 최대 절전 모드 메이븐 플러그인hbm2java 실패 : <mapping class = "com.dss.domain.Foo"/>로 선언 된 클래스를로드 할 수 없습니다.

<build> 
<plugins> 
    <plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>hibernate3-maven-plugin</artifactId> 
    <version>2.2</version> 
    <executions> 
     <execution> 
     <id>hbm2cfgxml</id> 
     <phase>generate-resources</phase> 
     <goals> 
      <goal>hbm2cfgxml</goal> 
     </goals> 
     <inherited>false</inherited> 
     <configuration> 
      <components> 
      <component> 
       <name>hbm2cfgxml</name> 
       <implementation>jdbcconfiguration</implementation> 
      </component> 
      </components> 
      <componentProperties> 
      <ejb3>true</ejb3> 
      <packagename>com.dss.domain</packagename> 
      </componentProperties> 
     </configuration> 
     </execution> 
     <execution> 
     <id>hbm2java</id> 
     <phase>generate-sources</phase> 
     <goals> 
      <goal>hbm2java</goal> 
     </goals> 
     <inherited>false</inherited> 
     <configuration> 
      <components> 
      <component> 
       <name>hbm2java</name> 
       <implementation>annotationconfiguration</implementation> 
      </component> 
      </components> 
      <componentProperties> 
      <ejb3>true</ejb3> 
      <packagename>com.dss.domain</packagename> 
      <configurationfile>target/hibernate3/generated-mappings/hibernate.cfg.xml</configurationfile> 
      </componentProperties> 
     </configuration> 
     </execution> 
    </executions> 
    <dependencies> 
     <dependency> 
     <groupId>mysql</groupId> 
     <artifactId>mysql-connector-java</artifactId> 
     <version>5.1.16</version> 
     </dependency> 
    </dependencies> 
    </plugin> 
</plugins> 

의 POM에서 추출물이다; 프로젝트 DSS 도메인에 hbm2java (hbm2java) : Hibernate3는-받는다는 - 플러그인 : 2.2 목표 org.codehaus의 실행 hbm2java하지만 hbm2java 메시지

목표를 org.codehaus.mojo을 실행하지 못했습니다

실패합니다. 모조 : Hibernate3는-받는다는 - 플러그인 : 2.2 : hbm2java가 실패 할 수 없습니다 는 클래스 = "com.dss.domain.Foo은"/> 구성에 클래스가 < 매핑 선언로드 -> [도움말 1]

나중에이 모든 것을 우리가 처리해야하는 JPA 구현으로 옮겨야합니다. ntly 가지고, 그래서 다른 질문은 구성 요소 속성 jpaconfiguration 전환해야합니까?

또한 최근 프로젝트 (Hibernate 3.6.6-FINAL)에서 최근에 uopd 된 것들에 대한 종속성을 업데이트하면 이들 중 아무 것도 작동하지 않는 것 같습니다. 그러나 이것은 별도의 질문입니다. here.

모든 포인터 또는 전체 솔루션은 ;-) 매우 환영

답변

0
내가 추가 hbm2hbmxml을 추가 할 때, 어쨌든 통해 찾아 보았다 유사한 게시물을 (내가 먼저 그것을 놓친 방법을 잘 모르는)되었지만

내 빌드; 빌드가 오류없이 실패하지 않습니다.

 <execution> 
     <id>hbm2hbmxml</id> 
     <phase>generate-resources</phase> 
     <goals> 
      <goal>hbm2hbmxml</goal> 
     </goals> 
     <inherited>false</inherited> 
     <configuration> 
      <components> 
      <component> 
       <name>hbm2hbmxml</name> 
       <outputDirectory>target/classes</outputDirectory> 
      </component> 
      </components> 
      <componentProperties> 
      <packagename>com.sapient.dss.dbci.domain</packagename> 
      </componentProperties> 
     </configuration> 
     </execution> 

그러나 이것은 내가 찾던 해결책이 아닙니다. hibernate.cfg.xml을 볼 때 .hbm.xmls를 가리키는 매핑 리소스를 사용하고 있습니다. 생성 된 Java 소스는 ​​JPA 주석을 사용하고 있습니다.

<?xml version="1.0" encoding="utf-8"?> 
<!DOCTYPE hibernate-configuration PUBLIC 
"-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> 
<hibernate-configuration> 
    <session-factory> 
     <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> 
     <property name="hibernate.connection.password">password</property> 
     <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/liquibrain</property> 
     <property name="hibernate.connection.username">liquibrain</property> 
     <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property> 
     <mapping resource="com/dss/domain/Foo.hbm.xml" /> 
     <mapping resource="com/dss/domain/Bar.hbm.xml" /> 
    </session-factory> 
</hibernate-configuration> 

여기에 생성 된 Java 소스에서 추출 년대의 hibernate.cfg.xml :

/** 
* Foo generated by hbm2java 
*/ 
@Entity 
@Table(name="iteration" 
    ,catalog="liquibrain" 
) 
public class Foo implements java.io.Serializable { 
... 
... 
@Id @GeneratedValue(strategy=IDENTITY) 

@Column(name="id", nullable=false) 
public Long getId() { 
    return this.id; 
} 

public void setId(Long id) { 
    this.id = id; 
} 
... 
... 
... 
@ManyToMany(fetch=FetchType.LAZY) 
    @JoinTable(name="bar_foos", joinColumns = { 
     @JoinColumn(name="foo_id", nullable=false, updatable=false) }, inverseJoinColumns = { 
     @JoinColumn(name="bar_id", nullable=false, updatable=false) }) 
    public Set getBars() { 
     return this.bars; 
    } 

모두 HBM 파일과 자바 소스가 JAR 패키지로 얻을하지만 이후 hibernate.cfg.xml은 .hbm.xml을 통한 매핑을 언급합니다. 그렇다면 POJO에서 매핑과 주석 구성의 형태로 정보를 복제하지 않고도 Java 소스를 생성 할 수있는 방법이 있습니까? 이전보다 플러그인에 대해 더 혼란스럽게합니다.

1

나는 maven으로 빌드 된 mysql과 함께 최대 절전 모드를 사용하고있다. hbm2hbmxml을 실행하는 대신 hbm2cfgxml 및 hbm2java 만 실행되도록 실행 목표를 변경했습니다. 이제는 내 프로젝트가 주석 기반의 pojos와 hibernate.cfg.xml을 생성합니다.

희망이 도움이됩니다.

내 구성을 참조하십시오 :

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.springpress</groupId> 
    <artifactId>hibernate</artifactId> 
    <version>1.0.0-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>hibernate</name> 
    <url>http://maven.apache.org</url> 

    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 

    <dependencies> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>3.8.1</version> 
      <scope>test</scope> 
     </dependency> 
     <!-- MySQL Connector --> 
     <dependency> 
      <groupId>mysql</groupId> 
      <artifactId>mysql-connector-java</artifactId> 
      <version>5.1.19</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-orm</artifactId> 
      <version>3.1.1.RELEASE</version> 
      <!-- will come with all needed Spring dependencies such as spring-core 
      and spring-beans --> 
     </dependency> 
     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-entitymanager</artifactId> 
      <version>4.1.1.Final</version> 
      <!-- will come with Hibernate core --> 
     </dependency> 
     <dependency> 
      <groupId>cglib</groupId> 
      <artifactId>cglib</artifactId> 
      <version>2.2.2</version> 
      <scope>runtime</scope> 
     </dependency> 
    </dependencies> 
    <build> 
     <plugins> 

      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>hibernate3-maven-plugin</artifactId> 
       <version>2.2</version> 
       <executions> 
        <execution> 
         <id>generate-xml-files</id> 
         <phase>generate-resources</phase> 
         <goals> 
          <!-- <goal>hbm2hbmxml</goal> --> 
          <goal>hbm2cfgxml</goal> 
         </goals> 
        </execution> 
        <execution> 
         <id>generate-entities</id> 
         <phase>generate-sources</phase> 
         <goals> 
          <goal>hbm2java</goal> 
         </goals> 
        </execution> 
       </executions> 
       <configuration> 
        <components> 
         <component> 
          <name>hbm2hbmxml</name> 
          <implementation>jdbcconfiguration</implementation> 
          <outputDirectory>target/classes</outputDirectory> 
         </component> 
         <component> 
          <name>hbm2cfgxml</name> 
          <implementation>jdbcconfiguration</implementation> 
          <outputDirectory>target/classes</outputDirectory> 
         </component> 
         <component> 
          <name>hbm2java</name> 
          <implementation>jdbcconfiguration</implementation> 
          <outputDirectory>target/generated-sources/hibernate</outputDirectory> 
         </component> 
        </components> 
        <componentProperties> 
         <propertyfile>src/main/resources/hibernate.properties</propertyfile> 
         <jdk5>true</jdk5> 
         <ejb3>true</ejb3> 
         <packagename>com.springpress.hibernate.entities</packagename> 
         <format>true</format> 
         <haltonerror>true</haltonerror> 
        </componentProperties> 
       </configuration> 
       <dependencies> 
        <dependency> 
         <groupId>cglib</groupId> 
         <artifactId>cglib-nodep</artifactId> 
         <version>2.2.2</version> 
        </dependency> 
        <dependency> 
         <groupId>mysql</groupId> 
         <artifactId>mysql-connector-java</artifactId> 
         <version>5.1.19</version> 
        </dependency></dependencies> 
       </plugin> 
      </plugins> 
     </build> 
    </project> 

을 그리고 내가 좋아하는 hibernate.properties 있습니다

hibernate.connection.driver_class=com.mysql.jdbc.Driver 
hibernate.connection.url=jdbc:mysql://localhost:3306/mydb 
hibernate.connection.username=root 
hibernate.connection.password=pass 
hibernate.dialect=org.hibernate.dialect.MySQLDialect 
hibernate.default_schema=mydb