When I do an export with the MappingTools to a sql file I cant' see my
Foreignkeys how does it come?
My persistenceFile looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" 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";>
        <persistence-unit name="RackManagerEJB" 
transaction-type="RESOURCE_LOCAL">
        
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
                <class>entities.Element</class>
                <class>entities.Property</class>
    <exclude-unlisted-classes />
                <properties>
                        <property name="openjpa.ConnectionURL"
value="jdbc:mysql://localhost:3306/rackmanagerdb" />
                        <property name="openjpa.ConnectionDriverName"
value="com.mysql.jdbc.Driver" />
      <property name="openjpa.ConnectionUserName" value="root" />
      <property name="openjpa.ConnectionPassword" value="root" />
      <property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO" />
      <property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(ForeignKeys=true)" />
      <property name="openjpa.jdbc.DBDictionary" value="mysql"/>
                </properties>
        </persistence-unit>
</persistence>


My Element entity like this:

@Entity
@Table(name="Element")
public class Element implements Serializable {

  private static final long serialVersionUID = 8689013550523480947L;

  public Element() {    
  }
  
  private String        id;
  private String        name;
  private String        description;
  private Set<Property> properties;
  private Element       parentElement;
  private Set<Element>  childElements;

  @Id
  public String getId() {
    return id;
  }
  
  public void setId(String id) {
    this.id = id;
  }
  
  public String getName() {
    return name;
  }
  
  public void setName(String name) {
    this.name = name;
  }
  
  public String getDescription() {
    return description;
  }
  
  public void setDescription(String description) {
    this.description = description;
  }
  
  @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER,
mappedBy="element")
  public Set<Property> getProperties() {
    return properties;
  }
  
  public void setProperties(Set<Property> properties) {
    this.properties = properties;
  }
  
  @ManyToOne(optional=true)
  @ForeignKey(name="FK_parent_element")
  @JoinColumn(name="parent_Element", referencedColumnName="id")
  public Element getParentElement() {
    return parentElement;
  }
  
  public void setParentElement(Element parentElement) {
    this.parentElement = parentElement;
  }
  
  @OneToMany(mappedBy="parentElement")
  public Set<Element> getChildElements() {
    return childElements;
  }
  
  public void setChildElements(Element childElement) {
    this.childElements.add(childElement);
  }
  
}


my property like this:

@Entity
@Table(name="Property")
public class Property implements Serializable {

  private static final long serialVersionUID = -6988886476498387460L;

  public Property() {    
  }
  
  private int     id;
  private String  property;
  private String  value;
  private Element element;
  
  @Id
  @GeneratedValue(strategy=GenerationType.AUTO)
  public int getId() {
    return id;
  }
  
  public void setId(int id) {
    this.id = id;
  }
  
  public String getProperty() {
    return property;
  }
  
  public void setProperty(String property) {
    this.property = property;
  }
  
  public String getValue() {
    return value;
  }
  
  public void setValue(String value) {
    this.value = value;
  }

  @ManyToOne(fetch=FetchType.LAZY)
  @ForeignKey(name="FK_property_element")
  @JoinColumn(name="element", nullable=false)
  public Element getElement() {
    return element;
  }

  public void setElement(Element element) {
    this.element = element;
  }
    
}

my SQL output file:
CREATE TABLE Element (id VARCHAR(255) NOT NULL, description VARCHAR(255),
name VARCHAR(255), parent_Element VARCHAR(255), PRIMARY KEY (id)) TYPE =
innodb;
CREATE TABLE OPENJPA_SEQUENCE_TABLE (ID TINYINT NOT NULL, SEQUENCE_VALUE
BIGINT, PRIMARY KEY (ID)) TYPE = innodb;
CREATE TABLE Property (id INTEGER NOT NULL, property VARCHAR(255), value
VARCHAR(255), element VARCHAR(255) NOT NULL, PRIMARY KEY (id)) TYPE =
innodb;
CREATE INDEX I_ELEMENT_PARENTELEMENT ON Element (parent_Element);
CREATE INDEX I_PROPRTY_ELEMENT ON Property (element);

Did I forgot some thing to configurate or is the foreign key not supported?

Greets K

-- 
View this message in context: 
http://n2.nabble.com/Set-ForeignKey-tp3828908p3828908.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to