Hyperjaxb2 Schwierigkeiten mit Cascade

binoffline

Grünschnabel
Hi zusammen,

Ich habe mich an Hyperjaxb2 gewagt und habe nun das folgende Problem und zwar habe ich ein Datenbankschema erstellt und aus diesem werden nun mit Hilfe von XJC Compiler die Source Dateien erzeugt und die Hibernate Mappings.
Arbeite mit J2EE

Das sieht dann in etwa so aus…..

Schema.xsd
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:mose="http://mogawe.org/mose"
targetNamespace="http://mogawe.org/mose"
xmlns:hj="http://hyperjaxb2.jvnet.org/customizations"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
jaxb:extensionBindingPrefixes="hj"
jaxb:version="1.0">

<annotation>
<appinfo>
<jaxb:globalBindings generateIsSetMethod="true"/>
<jaxb:schemaBindings>
<jaxb:package name="de.economore.mogawe.mose.dao"/>
</jaxb:schemaBindings>
</appinfo>
</annotation>

<element name="phoneNumber" type="mose:phoneNumberType"/>
<complexType name="phoneNumberType">
<attribute name="moseIdentifier" type="ID" use="optional">
<annotation>
<appinfo>
<hj:id>
<hj:generator generatorClass="uuid" />
</hj:id>
</appinfo>
</annotation>
</attribute>
<attribute name="phoneNumber" type="long" use="required" />
<attribute name="numberName" type="string" use="optional" />
<attribute name="numberDescription" type="string"
use="optional" />
</complexType>

<element name="pbxAccount" type="mose:pbxAccountType"></element>
<complexType name="pbxAccountType">
<attribute name="moseIdentifier" type="ID" use="optional">
<annotation>
<appinfo>
<hj:id>
<hj:generator generatorClass="uuid" />
</hj:id>
</appinfo>
</annotation>
</attribute>
<attribute name="voipType" type="string" use="optional"
default="sip">
</attribute>
<attribute name="voipAccount" type="string" use="required"></attribute>
<attribute name="voipHost" type="string" use="optional"></attribute>
<attribute name="password" type="string" use="optional"></attribute>
<attribute name="voipUsage" type="int" use="optional" default="0"></attribute>
</complexType>



<complexType name="ringDeskPhoneActionType">
<complexContent>
<extension base="mose:synchronousActionType">
<sequence>
<element name="destinationPbxAccount" type="mose:pbxAccountType"
minOccurs="1" maxOccurs="1">
</element>
<element name="destinationPhoneNumber" type="mose:phoneNumberType"
minOccurs="1" maxOccurs="1">
</element>
</sequence>
</extension>
</complexContent>
</complexType>
</schema>

und hier die Hibernate Mappings

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping auto-import="false" default-cascade="all-delete-orphan" default-lazy="false">
<class discriminator-value="[de.economore.mogawe.mose.dao.PhoneNumberType]"
name="de.economore.mogawe.mose.dao.PhoneNumberType"
table="PhoneNumberType">
<id access="org.jvnet.hyperjaxb2.runtime.hibernate.accessor.CheckingPropertyAccessor"
name="MoseIdentifier"
type="org.hibernate.type.StringType">
<generator class="uuid"/>
</id>
<discriminator type="org.hibernate.type.StringType">
<column name="Hjtype"/>
</discriminator>
<property access="org.jvnet.hyperjaxb2.runtime.hibernate.accessor.CheckingPropertyAccessor"
name="NumberName">
<column name="NumberName"/>
<type name="org.hibernate.type.StringType"/>
</property>
<property access="org.jvnet.hyperjaxb2.runtime.hibernate.accessor.CheckingPropertyAccessor"
name="PhoneNumber">
<column name="PhoneNumber"/>
<type name="org.hibernate.type.LongType"/>
</property>
<property access="org.jvnet.hyperjaxb2.runtime.hibernate.accessor.CheckingPropertyAccessor"
name="NumberDescription">
<column name="NumberDescription"/>
<type name="org.hibernate.type.StringType"/>
</property>
<subclass discriminator-value="de.economore.mogawe.mose.dao.PhoneNumberType"
name="de.economore.mogawe.mose.dao.impl.PhoneNumberTypeImpl"/>
</class>
</hibernate-mapping>
-----------------------------------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping auto-import="false" default-cascade="all-delete-orphan" default-lazy="false">
<class discriminator-value="[de.economore.mogawe.mose.dao.PbxAccountType]"
name="de.economore.mogawe.mose.dao.PbxAccountType"
table="PbxAccountType">
<id access="org.jvnet.hyperjaxb2.runtime.hibernate.accessor.CheckingPropertyAccessor"
name="MoseIdentifier"
type="org.hibernate.type.StringType">
<generator class="uuid"/>
</id>
<discriminator type="org.hibernate.type.StringType">
<column name="Hjtype"/>
</discriminator>
<property access="org.jvnet.hyperjaxb2.runtime.hibernate.accessor.CheckingPropertyAccessor"
name="VoipHost">
<column name="VoipHost"/>
<type name="org.hibernate.type.StringType"/>
</property>
<property access="org.jvnet.hyperjaxb2.runtime.hibernate.accessor.CheckingPropertyAccessor"
name="Password">
<column name="Password"/>
<type name="org.hibernate.type.StringType"/>
</property>
<property access="org.jvnet.hyperjaxb2.runtime.hibernate.accessor.CheckingPropertyAccessor"
name="VoipAccount">
<column name="VoipAccount"/>
<type name="org.hibernate.type.StringType"/>
</property>
<property access="org.jvnet.hyperjaxb2.runtime.hibernate.accessor.CheckingPropertyAccessor"
name="VoipUsage">
<column name="VoipUsage"/>
<type name="org.hibernate.type.IntegerType"/>
</property>
<property access="org.jvnet.hyperjaxb2.runtime.hibernate.accessor.CheckingPropertyAccessor"
name="VoipType">
<column name="VoipType"/>
<type name="org.hibernate.type.StringType"/>
</property>
<subclass discriminator-value="de.economore.mogawe.mose.dao.PbxAccountType"
name="de.economore.mogawe.mose.dao.impl.PbxAccountTypeImpl"/>
</class>
</hibernate-mapping>

------------------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping auto-import="false" default-cascade="all-delete-orphan" default-lazy="false">
<subclass discriminator-value="[de.economore.mogawe.mose.dao.RingDeskPhoneActionType]"
extends="de.economore.mogawe.mose.dao.SynchronousActionType"
name="de.economore.mogawe.mose.dao.RingDeskPhoneActionType">
<join table="RingDeskPhoneActionType">
<key>
<column name="Hjid"/>
</key>
<many-to-one class="de.economore.mogawe.mose.dao.PbxAccountType"
name="DestinationPbxAccount">
<column name="DestinationPbxAccount"/>
</many-to-one>
<many-to-one class="de.economore.mogawe.mose.dao.PhoneNumberType"
name="DestinationPhoneNumber">
<column name="DestinationPhoneNumber"/>
</many-to-one>
</join>
<subclass discriminator-value="de.economore.mogawe.mose.dao.RingDeskPhoneActionType"
name="de.economore.mogawe.mose.dao.impl.RingDeskPhoneActionTypeImpl"/>
</subclass>
</hibernate-mapping>

Das Schema ist sehr groß also habe ich nur die relevanten Typen raus genommen.
Ich habe jetzt ein Typen RingDeskPhoneActionType dieser wiederum hat einmal den PbxAccountType und den PhoneNumberType. Soweit so gut, es klappt auch alles alle nötigen XML Fils werden angelegt und Hibernate erstellt auch die dazugehörigen tabellen.
Wenn ich jetzt eine RingDeskPhoneActionType speichern würde und diesem danach ein neue PbxAccount oder PhoneNumber zuteile dann würde er die alten einfach aus der Datenbank löschen da Hibernate cascade="all-delete-orphan" setzt.

Ich könnte nun hingehen und in jedem Hibernate Mapping den wert cascade auf „none“ setzen, damit würde er die PhoneNumbers und PbxAccounts nicht mehr löschen. Aber sobald ich dann mit dem Schema die Source Dateien neu generiere sind die ganzen einträge weg und es ist wieder alles auf cascade="all-delete-orphan" gesetzt.

Ich müsste also schon irgendwo im Schema einstellen können das beim löschen oder verändern von RingDeskPhoneActionType die PhonNumber und PbxAccounts nicht gelöscht werden sollen.

Es soll über die Annotationen möglich sein, aber wie?
Meine Frage jetzt an die Profis wie stelle ich im Schema cascade individuell ein, so das es auch in die Hibernate Mappings übernommen wird

Wäre für jeden Vorschlag dankbar
 
Zuletzt bearbeitet:
Zurück