-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Relationship mapping problem: broken column mapping
PostPosted: Fri Jun 23, 2006 4:21 pm 
Newbie

Joined: Fri Jun 23, 2006 3:40 pm
Posts: 11
I'm having problems with JPA relationship mappings that i'm trying to create for an existing database schema. The part of the schema i'm having problems consists of 3 tables: share, filter and filter_command.

A share represents a directory tree which a crawler traverses. For each file found in the directory tree 0-n filter commands are executed (in specified order). There's 0-n filters for each share (unidirectional) and 1 filter_command per filter (unidirectional).

I'm getting the following exception when trying to run the application:

Caused by: javax.persistence.PersistenceException: org.hibernate.MappingException: broken column mapping for: cmd.id of: spider2.config.Filter


Here's the database schema description and some sample data:

CREATE TABLE share (
path VARCHAR(255),
PRIMARY KEY(path)
);

CREATE TABLE filter_command (
name VARCHAR(255) NOT NULL,
command VARCHAR(255) NOT NULL,
PRIMARY KEY(name)
);

CREATE TABLE filter (
share_path VARCHAR(255) NOT NULL,
command_name VARCHAR(255) NOT NULL,
filter_order int NOT NULL,
FOREIGN KEY(share_path) REFERENCES share(path),
FOREIGN KEY(command_name) REFERENCES filter_command(name),
PRIMARY KEY(share_path, command_name)
);

INSERT INTO share VALUES ('/etc');
INSERT INTO filter_command VALUES ('cat', '/bin/cat');
INSERT INTO filter_command VALUES ('ls', '/bin/ls');
INSERT INTO filter VALUES ('/etc', 'cat', 1);
INSERT INTO filter VALUES ('/etc', 'ls', 2);


The entity annotations look like this:

@Entity
@Table(name="share")
public class Share {
@Id
@Column(name="path")
private String path;

@OneToMany
@OrderBy("order ASC")
@JoinColumn(name="share_path", referencedColumnName="path")
private Collection<Filter> filters;
}

@Entity
@IdClass(FilterPK.class)
@Table(name="filter")
public class Filter {
@Id
@Column(name="share_path")
private String path;

@Id
@Column(name="command_name")
private String filter;

@Column(name="filter_order")
private int order;

@OneToOne
@JoinColumn(name="command_name", referencedColumnName="name")
private FilterCommand cmd;
}

public class FilterPK implements Serializable {
@Column(name="share_path")
public String path;

@Column(name="command_name")
public String filter;
}

@Entity
@Table(name="filter_command")
public class FilterCommand {
@Id
@Column(name="name")
private String name;

@Column(name="command")
private String command;
}

Am i doing something wrong in defining the IdClass or relationship mappings?



Here's the full exception stack trace i'm getting:

Exception in thread "main" java.lang.ExceptionInInitializerError
at spider2.Crawler.crawl(Unknown Source)
at spider2.Crawler.main(Unknown Source)
Caused by: javax.persistence.PersistenceException: org.hibernate.MappingException: broken column mapping for: cmd.id of: spider2.config.Filter
at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:217)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:114)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:27)
at spider2.config.SpiderConfig.readConfig(Unknown Source)
at spider2.config.SpiderConfig.<init>(Unknown Source)
at spider2.config.SpiderConfig.<clinit>(Unknown Source)
... 2 more
Caused by: org.hibernate.MappingException: broken column mapping for: cmd.id of: spider2.config.Filter
at org.hibernate.persister.entity.AbstractPropertyMapping.initPropertyPaths(AbstractPropertyMapping.java:122)
at org.hibernate.persister.entity.AbstractPropertyMapping.initIdentifierPropertyPaths(AbstractPropertyMapping.java:176)
at org.hibernate.persister.entity.AbstractPropertyMapping.initPropertyPaths(AbstractPropertyMapping.java:160)
at org.hibernate.persister.entity.AbstractEntityPersister.initOrdinaryPropertyPaths(AbstractEntityPersister.java:1628)
at org.hibernate.persister.entity.AbstractEntityPersister.initPropertyPaths(AbstractEntityPersister.java:1656)
at org.hibernate.persister.entity.AbstractEntityPersister.postConstruct(AbstractEntityPersister.java:2699)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:386)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:223)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1213)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:631)
at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:760)
at org.hibernate.ejb.Ejb3Configuration.createFactory(Ejb3Configuration.java:151)
at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:205)
... 8 more



Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 28, 2006 12:12 pm 
Newbie

Joined: Wed Jun 21, 2006 5:46 am
Posts: 10
Location: Finland
Quote:
Caused by: javax.persistence.PersistenceException: org.hibernate.MappingException: broken column mapping for: cmd.id of: spider2.config.Filter

The Exception says that the problem is in FilterCommand cmd field mapping in Filter class, where you have @OneToOne annotation.

I think you should use @ManyToOne annotation, since the same FilterCommand object can be used from several Filter objects. Because FilterCommand cmd field also maps to same database column (command_name) as Id field String filter, it should not be used for inserts (insertable=false, updatable=false).

Try this one and see if it works.
Code:
@Entity
@IdClass(FilterPK.class)
@Table(name="filter")
public class Filter {
  @Id
  @Column(name="share_path")
  private String path;
 
  @Id
  @Column(name="command_name")
  private String filter;
 
  @Column(name="filter_order")
  private int order;
 
  @ManyToOne
  @JoinColumn(name="command_name", referencedColumnName="name", insertable=false, updatable=false)
  private FilterCommand cmd;
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 29, 2006 2:22 pm 
Newbie

Joined: Fri Jun 23, 2006 3:40 pm
Posts: 11
bloso wrote:
Quote:
I think you should use @ManyToOne annotation, since the same FilterCommand object can be used from several Filter objects. Because FilterCommand cmd field also maps to same database column (command_name) as Id field String filter, it should not be used for inserts (insertable=false, updatable=false).


The mapping you suggested seems to be working, thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 29, 2006 9:52 pm 
Newbie

Joined: Wed Jun 21, 2006 5:46 am
Posts: 10
Location: Finland
Glad I could help :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.