-->
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: Could not determine type for: java.util.Collection
PostPosted: Sat Sep 23, 2006 2:30 pm 
Newbie

Joined: Thu Jun 22, 2006 7:19 am
Posts: 14
Directly. I use Hibernate 3.2 and hibernate-annotations 3.2.0CR2. I have three tables:

Compu:
compid: int
name: varchar
description: varchar
ipaddress: varchar

Compugr:
compugrid: int
name: varchar
description: varchar

Compugrmem:
compugrmemid: int
compuid: int
compugrid: int

A computer belongs to zero or more groups and a group contains zero or more computers. I use annotations:

HibernateUtil.java

Code:
public class HibernateUtil {

    private static SessionFactory sessionFactory;

    public static void initialize(String hibernateConfigFile) {
        try {
            // Create the SessionFactory from hibernate.cfg.xml
            sessionFactory = new AnnotationConfiguration().configure(new File(hibernateConfigFile)).buildSessionFactory();
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }

}


Base.java
Code:
@MappedSuperclass
public class Base {

    private static Logger log = Logger.getLogger(Base.class);

    @Id()
    private int id;


    private String name;


    private String decription;

    protected Base() {
        log.debug("Creando nuevo objeto.");
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDecription() {
        return decription;
    }

    public void setDecription(String decription) {
        this.decription = decription;
    }

    @Transient
    public void save() {

        log.debug("Guardando el objeto...");

        SessionFactory sf = HibernateUtil.getSessionFactory();
        Session session = sf.getCurrentSession();
        session.beginTransaction();
        session.save(this);
        session.getTransaction().commit();

        log.debug("Objeto guardado.");

    }

}


Computer.java
Code:
@Entity()
@Table(name="COMPU")
@AttributeOverride( name="id", column = @Column(name="COMPID") )
public class Computer extends Base {

    private Collection<ComputerGroup> computerGroupList;
    private String ipAddress;

    public Computer() {
    }

    @Transient
    @ManyToMany(
        cascade={CascadeType.PERSIST, CascadeType.MERGE},
        mappedBy="computersList",
        targetEntity=ComputerGroup.class
    )
    public Collection<ComputerGroup> getComputerGroupList() {
        return computerGroupList;
    }

    public void setComputerGroupList(Collection<ComputerGroup> computerGroupList) {
        this.computerGroupList = computerGroupList;
    }

    public String getIpAddress() {
        return ipAddress;
    }

    public void setIpAddress(String ipAddress) {
        this.ipAddress = ipAddress;
    }

}


ComputerGroup.java
Code:
@Entity()
@Table(name="COMPU")
@AttributeOverride( name="id", column = @Column(name="COMPID") )
public class Computer extends Base {

    private Collection<ComputerGroup> computerGroupList;
    private String ipAddress;

    public Computer() {
    }

    @Transient
    @ManyToMany(
        cascade={CascadeType.PERSIST, CascadeType.MERGE},
        mappedBy="computersList",
        targetEntity=ComputerGroup.class
    )
    public Collection<ComputerGroup> getComputerGroupList() {
        return computerGroupList;
    }

    public void setComputerGroupList(Collection<ComputerGroup> computerGroupList) {
        this.computerGroupList = computerGroupList;
    }

    public String getIpAddress() {
        return ipAddress;
    }

    public void setIpAddress(String ipAddress) {
        this.ipAddress = ipAddress;
    }

}



When the servlet starts, I get this error:

Code:
Initial SessionFactory creation failed.org.hibernate.MappingException: Could not determine type for: java.util.Collection, for columns: [org.hibernate.mapping.Column(computerGroupList)]


Any idea?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 23, 2006 3:47 pm 
Beginner
Beginner

Joined: Thu Aug 24, 2006 6:01 am
Posts: 49
Location: sophia-antipolis, France
Hi,

Why do you have @Transient for the getComputerGroupList? I don't think you should have that there.

Also, I don't think you need the @Transient on the save() method because it won't be interpreted by Hibernate as a property accessor.

Otherwise, you have posted the same code for ComputerGroup as for Computer.

kim


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 23, 2006 4:47 pm 
Newbie

Joined: Thu Jun 22, 2006 7:19 am
Posts: 14
Ummm.... Ctrl+C, Ctrl+V.... bad bad bad.

I have removed @Transient from Computer.getComputerGroupList() but the error continues. This is the code from ComputerGroup.java:

Code:

@javax.persistence.Entity()
@javax.persistence.Table(name="COMPUGR")
@AttributeOverride( name="id", column = @Column(name="COMPUGRID") )
public class ComputerGroup extends Base {

    private Collection<Computer> computersList;


    public ComputerGroup() {
    }

    @ManyToMany(targetEntity=Computer.class,
        cascade={CascadeType.PERSIST, CascadeType.MERGE}
    )
    @JoinTable(name="COMPUGRMEM",
        joinColumns={@JoinColumn(name="COMPUGRID")},
        inverseJoinColumns={@JoinColumn(name="COMPUID")}
    )
    public Collection<Computer> getComputersList() {
        return computersList;
    }

    public void setComputersList(Collection<Computer> computersList) {
        this.computersList = computersList;
    }

}


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 24, 2006 3:55 pm 
Beginner
Beginner

Joined: Thu Aug 24, 2006 6:01 am
Posts: 49
Location: sophia-antipolis, France
Hi,

your problem is your annotation of "id" in the class Base. You need to move it from the property declaration to the accessor method (getId()).

kim


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.