Note: Referenced from the Seam folk back to this forum. Hope that this is the right place...
Reference
http://www.jboss.com/index.html?module=bb&op=viewtopic&t=124459
When deploying the included generated classes, we get the following error.
Code:
javax.persistence.PersistenceException: org.hibernate.HibernateException: Wrong column type: guideid
, expected: varchar(4)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:720)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersisten
ce.java:127)
at org.jboss.ejb3.entity.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:246)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
The guideid is an integer column in the DB. Oddly, when we use an older version of the Hibernate tools (using hbm.xml files vs. annotations, which might be the issue), it works just fine. What am I missing here? TIA. And, apologies if this is the wrong forum...
VersionsHibernate 3.2.4.sp1
Hibernate Annotations 3.2.1.GA
Hibernate EntityManager 3.2.1.GA
Generated with Hibernate Tools 3.2.0.b10
DBPostgres 8.2
DB SchemaCode:
-- Table: avt_region_states
-- DROP TABLE avt_region_states;
CREATE TABLE avt_region_states
(
state character varying NOT NULL DEFAULT 64,
guideid integer NOT NULL,
code character varying(4) NOT NULL,
id serial NOT NULL,
CONSTRAINT auto_region_states_pk PRIMARY KEY (id),
CONSTRAINT auc_reg_states_auc_reg_fk1 FOREIGN KEY (guideid, code)
REFERENCES avt_regions (guideid, code) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITHOUT OIDS;
ALTER TABLE avt_region_states OWNER TO postgres;
-- Index: fki_auc_reg_states_auc_reg_fk1
-- DROP INDEX fki_auc_reg_states_auc_reg_fk1;
CREATE INDEX fki_auc_reg_states_auc_reg_fk1
ON avt_region_states
USING btree
(guideid, code);
-- Table: avt_regions
-- DROP TABLE avt_regions;
CREATE TABLE avt_regions
(
guideid integer NOT NULL,
code character varying(4) NOT NULL,
description character varying(64) NOT NULL,
CONSTRAINT auc_regions_pk PRIMARY KEY (guideid, code),
CONSTRAINT auc_regions_auc_guides FOREIGN KEY (guideid)
REFERENCES avt_guides (avtguideid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITHOUT OIDS;
ALTER TABLE avt_regions OWNER TO postgres;
Mappings /Annotated classesCode:
package com.r.model.seam;
// Generated Nov 19, 2007 3:46:16 PM by Hibernate Tools 3.2.0.b10
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;
/**
* AvtRegionStates generated by hbm2java
*/
@Entity
@Table(name="avt_region_states"
,schema="public"
)
public class AvtRegionStates implements java.io.Serializable {
private int id;
private AvtRegions avtRegions;
private String state;
public AvtRegionStates() {
}
public AvtRegionStates(int id, AvtRegions avtRegions, String state) {
this.id = id;
this.avtRegions = avtRegions;
this.state = state;
}
@Id
@Column(name="id", unique=true, nullable=false)
@NotNull
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumns( {
@JoinColumn(name="guideid", nullable=false),
@JoinColumn(name="code", nullable=false) } )
@NotNull
public AvtRegions getAvtRegions() {
return this.avtRegions;
}
public void setAvtRegions(AvtRegions avtRegions) {
this.avtRegions = avtRegions;
}
@Column(name="state", nullable=false, length=0)
@NotNull
@Length(max=0)
public String getState() {
return this.state;
}
public void setState(String state) {
this.state = state;
}
}
package com.r.model.seam;
// Generated Nov 19, 2007 3:46:16 PM by Hibernate Tools 3.2.0.b10
import java.util.HashSet;
import java.util.Set;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;
/**
* AvtRegions generated by hbm2java
*/
@Entity
@Table(name="avt_regions"
,schema="public"
)
public class AvtRegions implements java.io.Serializable {
private AvtRegionsId id;
private AvtGuides avtGuides;
private String description;
private Set<AvtRegionStates> avtRegionStateses = new HashSet<AvtRegionStates>(0);
private Set<AvtResults> avtResultses = new HashSet<AvtResults>(0);
public AvtRegions() {
}
public AvtRegions(AvtRegionsId id, AvtGuides avtGuides, String description) {
this.id = id;
this.avtGuides = avtGuides;
this.description = description;
}
public AvtRegions(AvtRegionsId id, AvtGuides avtGuides, String description, Set<AvtRegionStates> avtRegionStateses, Set<AvtResults> avtResultses) {
this.id = id;
this.avtGuides = avtGuides;
this.description = description;
this.avtRegionStateses = avtRegionStateses;
this.avtResultses = avtResultses;
}
@EmbeddedId
@AttributeOverrides( {
@AttributeOverride(name="guideid", column=@Column(name="guideid", nullable=false) ),
@AttributeOverride(name="code", column=@Column(name="code", nullable=false, length=4) ) } )
@NotNull
public AvtRegionsId getId() {
return this.id;
}
public void setId(AvtRegionsId id) {
this.id = id;
}
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="guideid", nullable=false, insertable=false, updatable=false)
@NotNull
public AvtGuides getAvtGuides() {
return this.avtGuides;
}
public void setAvtGuides(AvtGuides avtGuides) {
this.avtGuides = avtGuides;
}
@Column(name="description", nullable=false, length=64)
@NotNull
@Length(max=64)
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="avtRegions")
public Set<AvtRegionStates> getAvtRegionStateses() {
return this.avtRegionStateses;
}
public void setAvtRegionStateses(Set<AvtRegionStates> avtRegionStateses) {
this.avtRegionStateses = avtRegionStateses;
}
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="avtRegions")
public Set<AvtResults> getAvtResultses() {
return this.avtResultses;
}
public void setAvtResultses(Set<AvtResults> avtResultses) {
this.avtResultses = avtResultses;
}
}
package com.r.model.seam;
// Generated Nov 19, 2007 3:46:16 PM by Hibernate Tools 3.2.0.b10
import java.util.HashSet;
import java.util.Set;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;
/**
* AvtGuides generated by hbm2java
*/
@Entity
@Table(name="avt_guides"
,schema="public"
)
public class AvtGuides implements java.io.Serializable {
private int guideid;
private String name;
private Set<AvtRegions> avtRegionses = new HashSet<AvtRegions>(0);
public AvtGuides() {
}
public AvtGuides(int guideid) {
this.guideid = guideid;
}
public AvtGuides(int guideid, String name, Set<AvtRegions> avtRegionses) {
this.guideid = guideid;
this.name = name;
this.avtRegionses = avtRegionses;
}
@Id
@Column(name="guideid", unique=true, nullable=false)
@NotNull
public int getguideid() {
return this.guideid;
}
public void setguideid(int guideid) {
this.guideid = guideid;
}
@Column(name="name", length=256)
@Length(max=256)
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="AvtGuides")
public Set<AvtRegions> getAvtRegionses() {
return this.avtRegionses;
}
public void setAvtRegionses(Set<AvtRegions> avtRegionses) {
this.avtRegionses = avtRegionses;
}
}
Full stack trace of any exception that occurs:Code:
Caused by: org.hibernate.HibernateException: Wrong column type: guideid, expected: varchar(4)
at org.hibernate.mapping.Table.validateColumns(Table.java:261)
at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1083)
at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:116)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:317)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:713)
... 145 more
[/url]