Hi,
Am using Hibernate 2.1,mysql4.0.18...
When I generate my tables they all work fine apart from the SubSection_Page table..! I am using the @hibernate.id to hopefully generate an auto incrementing primary key on the SubSection_Page tablepaegLinkId column, but instead there are no auto incrementing columns but a primary key constructed from the subsection_id and ind columns is generated...!
Java Source:
package com.sovision.cmsCore.persistence;
import org.appfuse.persistence.BaseObject;
/**
* This class represents the website pages.
*
* @hibernate.class table="SubSection_Page"
*
* @author julian
*
*/
public class PageLink extends BaseObject {
///////////////////////////////////////
// attributes
protected Long pageLinkId;
protected Page linkedPage;
protected SubSection subSection;
protected int order;
/**
* Returns the pageLinkId.
*
* @return Long
*
* @hibernate.id generator-class="increment"
*
*
*/
public Long getPageLinkId() {
return pageLinkId;
}
/**
* @hibernate.many-to-one column="Page_ID" class="com.sovision.cmsCore.persistence.Page"
*
* @return Page
*
*/
public Page getLinkedPage() {
return linkedPage;
}
/**
* @hibernate.many-to-one column="SubSection_ID" class="com.sovision.cmsCore.persistence.SubSection"
*
* @return SubSection
*
*/
public SubSection getSubSection() {
return subSection;
}
/**
* @hibernate.property column="Ind" not-null="true" insert="false" update="false"
*
* @return int
*/
public int getOrder() {
return order;
}
/**
* @param i
*/
public void setPageLinkId(Long i) {
pageLinkId = i;
}
/**
* @param linkedPage
*/
public void setLinkedPage(Page page) {
this.linkedPage = page;
}
/**
* @param section
*/
public void setSubSection(SubSection section) {
subSection = section;
}
/**
* @param i
*/
public void setOrder(int i) {
order = i;
}
}
schema output file for subsection_page table..!
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="com.sovision.cmsCore.persistence.PageLink"
table="SubSection_Page"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="pageLinkId"
column="pageLinkId"
type="java.lang.Long"
>
<generator class="increment">
</generator>
</id>
<many-to-one
name="linkedPage"
class="com.sovision.cmsCore.persistence.Page"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="Page_ID"
/>
<many-to-one
name="subSection"
class="com.sovision.cmsCore.persistence.SubSection"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="SubSection_ID"
/>
<property
name="order"
type="int"
update="false"
insert="false"
column="Ind"
not-null="true"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-PageLink.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
Tables:
[schemaexport] create table SubSection (
[schemaexport] subSectionId BIGINT NOT NULL AUTO_INCREMENT,
[schemaexport] live BIT not null,
[schemaexport] section BIGINT not null,
[schemaexport] title VARCHAR(255) not null,
[schemaexport] url VARCHAR(255),
[schemaexport] ord INTEGER not null,
[schemaexport] list BIT not null,
[schemaexport] restricted BIT not null,
[schemaexport] primary key (subSectionId)
[schemaexport] )
[schemaexport] create table Section (
[schemaexport] sectionId BIGINT NOT NULL AUTO_INCREMENT,
[schemaexport] title VARCHAR(60) not null,
[schemaexport] ord INTEGER,
[schemaexport] live BIT not null,
[schemaexport] primary key (sectionId)
[schemaexport] )
[schemaexport] create table user_role (
[schemaexport] id BIGINT NOT NULL AUTO_INCREMENT,
[schemaexport] user_id BIGINT not null,
[schemaexport] username VARCHAR(255) not null,
[schemaexport] role_name VARCHAR(255) not null,
[schemaexport] primary key (id)
[schemaexport] )
[schemaexport] create table app_user (
[schemaexport] id BIGINT NOT NULL AUTO_INCREMENT,
[schemaexport] username VARCHAR(255) not null unique,
[schemaexport] password VARCHAR(255) not null,
[schemaexport] firstName VARCHAR(255) not null,
[schemaexport] lastName VARCHAR(255) not null,
[schemaexport] address VARCHAR(255),
[schemaexport] city VARCHAR(255) not null,
[schemaexport] country VARCHAR(100),
[schemaexport] email VARCHAR(255) unique,
[schemaexport] phoneNumber VARCHAR(255),
[schemaexport] postalCode VARCHAR(255) not null,
[schemaexport] province VARCHAR(100),
[schemaexport] website VARCHAR(255),
[schemaexport] passwordHint VARCHAR(255),
[schemaexport] primary key (id)
[schemaexport] )
[schemaexport] create table role (
[schemaexport] name VARCHAR(255) not null,
[schemaexport] description VARCHAR(255),
[schemaexport] primary key (name)
[schemaexport] )
[schemaexport] create table SubSection_Page (
[schemaexport] pageLinkId BIGINT not null,
[schemaexport] Page_ID BIGINT,
[schemaexport] SubSection_ID BIGINT,
[schemaexport] Ind INTEGER not null,
[schemaexport] primary key (SubSection_ID, Ind)
[schemaexport] )
[schemaexport] create table Page (
[schemaexport] pageId BIGINT NOT NULL AUTO_INCREMENT,
[schemaexport] modified DATETIME not null,
[schemaexport] User_ID BIGINT,
[schemaexport] content TEXT,
[schemaexport] live BIT not null,
[schemaexport] title VARCHAR(255) not null,
[schemaexport] primary key (pageId)
[schemaexport] )
[schemaexport] alter table SubSection add index (section), add constraint FK93F1ACA5756F7EE5 foreign key (section) references Section (sectionId)
[schemaexport] alter table SubSection_Page add index (SubSection_ID), add constraint FKDB2A020968EB42F5 foreign key (SubSection_ID) references SubSection (subSectionId)
[schemaexport] alter table SubSection_Page add index (Page_ID), add constraint FKDB2A0209335364AB foreign key (Page_ID) references Page (pageId)
[schemaexport] alter table Page add index (User_ID), add constraint FK25D6AF5A7381EF foreign key (User_ID) references app_user (id)
[schemaexport] (hbm2ddl.SchemaExport 160 ) schema export complete
[schemaexport] (connection.DriverManagerConnectionProvider 137 ) cleaning up connection pool: jdbc:mysql://localhost:3306/socms?autoReconnect=true
BUILD SUCCESSFUL
Total time: 34 seconds
Any help would be most appreciated..
Julian
|