0

hj:generated-value tag を使用して、既存のプロパティを生成された識別子としてマークすることにより、hyperjaxb3 で生成されたクラスをカスタマイズしたいと考えています。私の bindings.jxb ファイルでは、Status の ID を識別子としてマークしていますが、生成されたエンティティには @GeneratedValue の注釈が付けられていません。したがって、Status テーブルの id フィールドは pkey としてマークされますが、データベースで自動インクリメントされません。

XML スキーマ定義:

<complexType name="Status">
<sequence>
<element name="id" type="long">
</element>
<element name="title" type="string"></element>
<element name="description" type="cm:LongText"></element>
</sequence>
</complexType>

bindings.xjb での Hyperjaxb3 のカスタマイズ:

<jaxb:bindings node="xs:complexType[@name='Status']">
            <jaxb:bindings node=".//xs:element[@name='id']">
                <hj:id> <hj:generated-value strategy="AUTO"/> 
                    </hj:id>
            </jaxb:bindings>
        </jaxb:bindings>

結果のクラス:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Status", propOrder = {
    "id",
    "title",
    "description"
})
@XmlRootElement(name = "status")
@Entity(name = "Status")
@Table(name = "STATUS")
@Inheritance(strategy = InheritanceType.JOINED)
public class Status
    implements Equals, HashCode
{

    protected long id;
    @XmlElement(required = true)
    protected String title;
    @XmlElement(required = true)
    protected String description;

    /**
     * Gets the value of the id property.
     * 
     */
    @Id
    @Column(name = "ID", scale = 0)
    public long getId() {
        return id;
    }

    /**
     * Sets the value of the id property.
     * 
     */
    public void setId(long value) {
        this.id = value;
    }

    @Transient
    public boolean isSetId() {
        return true;
    }
    ......

Postgres 9.2 で hibernate を jpa プロバイダーとして使用します。pom.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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>de.fhg.fokus.cm</groupId>
    <artifactId>fixEMobility</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>Fix eMobility</name>
    <dependencies>
        <dependency>
            <groupId>asm</groupId>
            <artifactId>asm</artifactId>
            <version>3.1</version>
        </dependency>
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.7.0</version>
        </dependency>
        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
            <version>3.1</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.dtd-parser</groupId>
            <artifactId>dtd-parser</artifactId>
            <version>1.0</version>
        </dependency>
    <dependency>
            <groupId>relaxngDatatype</groupId>
            <artifactId>relaxngDatatype</artifactId>
            <version>20020414</version>
        </dependency>
        <dependency>
            <groupId>com.sun.org.apache.xml.internal</groupId>
            <artifactId>resolver</artifactId>
            <version>20050927</version>
        </dependency>
        <dependency>
            <groupId>org.kohsuke.rngom</groupId>
            <artifactId>rngom</artifactId>
            <version>20061207</version>
        </dependency>
        <dependency>
            <groupId>com.sun.istack</groupId>
            <artifactId>istack-commons-tools</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-core-asl</artifactId>
            <version>1.1.1</version>
        </dependency>

        <dependency>
        <groupId>org.codehaus.jettison</groupId>
        <artifactId>jettison</artifactId>
        <version>1.1</version>
        <!-- <type>bundle</type> -->
    </dependency>

        <dependency>
        <groupId>net.sourceforge.jtds</groupId>
        <artifactId>jtds</artifactId>
        <version>1.2.6</version>
    </dependency>
    <dependency>
        <groupId>xml-apis</groupId>
        <artifactId>xml-apis</artifactId>
        <version>1.0.b2</version>
    </dependency>
    <dependency>
        <groupId>xmlunit</groupId>
        <artifactId>xmlunit</artifactId>
        <version>1.0</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xsom</groupId>
        <artifactId>xsom</artifactId>
        <version>20081112</version>
    </dependency>
    <dependency>
        <groupId>org.jvnet</groupId>
        <artifactId>mimepull</artifactId>
        <version>1.3</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring</artifactId>
        <version>2.0.7</version>
    </dependency>
<!-- dependencies from the hyperjaxb sample -->
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
        <version>1.0.0.Final</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>2.2.4-1</version>
    </dependency>
    <dependency>
        <groupId>org.jvnet.hyperjaxb3</groupId>
        <artifactId>hyperjaxb3-ejb-runtime</artifactId>
        <version>0.5.6</version>
    </dependency>

    <!-- Test dependencies -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.1</version>
    </dependency>

    <!-- Roundtrip -->
    <dependency>
        <groupId>org.jvnet.hyperjaxb3</groupId>
        <artifactId>hyperjaxb3-ejb-roundtrip</artifactId>
        <version>0.5.6</version>
    </dependency>

    <!-- Hibernate Dependencies -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>3.6.5.Final</version>
    </dependency>
    <!-- Database -->
    <!--Database dependency to test without installation-->
    <dependency>
        <groupId>hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
        <version>1.8.0.7</version>
        <scope>test</scope>
    </dependency>
    <!--For usage with Postgre 9.x-->
    <dependency>
        <groupId>postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.1-901.jdbc4</version>
    </dependency>
    <!-- Jax Rs Dependencies -->
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>1.2</version>
        <!-- <type>bundle</type> -->
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-client</artifactId>
        <version>1.2</version>
        <!-- <type>bundle</type> -->
    </dependency>
    <dependency>
        <groupId>com.sun.jersey.contribs</groupId>
        <artifactId>jersey-multipart</artifactId>
        <version>1.8</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>
</dependencies>
<repositories>
    <repository>
        <id>maven2-repository.jboss.com</id>
        <url>http://repository.jboss.com/maven2</url>
    </repository>
</repositories>
<build>
    <defaultGoal>install</defaultGoal>
    <plugins>
        <plugin>
            <groupId>org.jvnet.hyperjaxb3</groupId>
            <artifactId>maven-hyperjaxb3-plugin</artifactId>
            <version>0.5.6</version>
            <executions>
                <execution>
                <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
        <extension>true</extension>                          <roundtripTestClassName>RoundtripTest</roundtripTestClassName>
            </configuration>
        </plugin>
        <plugin>
            <inherited>true</inherited>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
    </plugins>
</build>

どんな助けでも大歓迎です。

4

1 に答える 1

0

orm:generated-value代わりに使用してください:

<jaxb:bindings node=".//xs:element[@name='id']">
   <hj:id> 
     <orm:generated-value strategy="AUTO"/> 
   </hj:id>
</jaxb:bindings>
于 2013-08-28T07:15:21.583 に答える