-->
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.  [ 2 posts ] 
Author Message
 Post subject: Could not determine type
PostPosted: Fri Mar 19, 2010 10:02 am 
Newbie

Joined: Fri Mar 19, 2010 9:49 am
Posts: 1
Hi
I have the following class:

Code:
@Entity
@Table(name = "Category")
public class Category {
   
   @Id
   @Column(name = "ID")
   private long id;
   @Column(name = "Name")
   private String name;
   @Column(name = "Description")
   private String description;
   @Column(name = "Parent")
        @JoinColumn(name = "ID")
   private Category parent;

   public Category(){}
   
   public Category(String n, String d, Category c){
      this.name = n;
      this.description = d;
      this.parent = c;
   }

   public long getId() {
      return 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;
   }

   public Category getParent() {
      return parent;
   }

   public void setParent(Category parent) {
      this.parent = parent;
   }
}



My DB is Mysql and the table looks like this:

Code:

mysql> describe category;
+-------------+--------------+------+-----+---------+----------------+
| Field       | Type         | Null | Key | Default | Extra          |
+-------------+--------------+------+-----+---------+----------------+
| ID          | bigint(20)   | NO   | PRI | NULL    | auto_increment |
| Name        | varchar(50)  | NO   |     | NULL    |                |
| Description | varchar(300) | YES  |     | NULL    |                |
| Parent      | bigint(20)   | YES  |     | NULL    |                |
+-------------+--------------+------+-----+---------+----------------+


And also have it in my hibernate.cfg.xml
Code:
<mapping package="papers.entities" />
        <mapping class="papers.entities.Category"/>


When I try to insert in Category:

Category cat = new Category("testCat", "test", new Category());
cdao.persistCategory(cat);

I get error:

org.hibernate.MappingException: Could not determine type for: papers.entities.Category, at table: Category, for columns: [org.hibernate.mapping.Column(Parent)]


Anyone has on idea what the problem is? It's been bothering me for hours.
Thank you


Top
 Profile  
 
 Post subject: Re: Could not determine type
PostPosted: Fri Mar 19, 2010 10:41 am 
Regular
Regular

Joined: Thu May 07, 2009 5:56 am
Posts: 94
Location: Toulouse, France
hi, just a tip...Annote your field with @OneToOne or @ManyToOne (Not @Column)

Code:
  @OneToOne
   @JoinColumn(name = "ID", nullable = true)
   private Category parent;

_________________
everything should be made as simple as possible, but not simpler (AE)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.