-->
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: Need some ideas on the mapping
PostPosted: Sun Feb 05, 2006 3:57 am 
Newbie

Joined: Fri Mar 19, 2004 8:11 pm
Posts: 3
I'm currently writing a web application, that will handle generic objects. So I will have most likely one object with a set of fields, that have a type and a value. I was wondering how to do the mapping. Any ideas?

So what I have so far:

package org.mendrik.suigeneris.model;

import org.apache.log4j.Logger;
import org.mendrik.suigeneris.meta.FieldSupport;
import org.mendrik.suigeneris.persistence.Dao;

import java.util.HashMap;
import java.util.Map;

/**
* @author Andreas Prudzilko
*/
public class Data extends ModelObject {

private FieldSupport fieldSupport;

[...]

public static final Dao<Data> DAO = new Dao<Data>(Data.class);

public Dao<? extends ModelObject> getDao() {
return DAO;
}

}

FieldSupport now holds basically a List of Field elements that consist of an unique key and a value. And of course it's all subclassed by classes like StringField, TextField, ImageField etc....

Now I'm kinda stuck on the mapping. My database layout though seems clear to me. I will have a Data table, a Data_Field table (for the set of fields to describe) and a Field table, that actually holds the values. Now I'm not sure if it's the smartest thing to do, but my Field table has columns for each possible value type:

field_id, name, stringvalue, textvalue, datevalue, numbervalue, ...

Any ideas how to do it better?

Oh and currently I'm also stuck with hibernate annotations.
I have:

new AnnotationConfiguration().configure("/config/hibernate.cfg.xml")
.addClass(Project.class)
.buildSessionFactory();

But it is still complaining about unknown entity project ?!
The cfg.xml holds only info about db connection.


Cheers,

Andreas


Top
 Profile  
 
 Post subject: Uhm...
PostPosted: Sun Feb 05, 2006 5:20 am 
Newbie

Joined: Fri Mar 19, 2004 8:11 pm
Posts: 3
Ok me again :-D

I can't get those annotations to run. And i followed the instructions from the docs.

Code:
<hibernate-configuration>

        [...]

        <!-- mapping files -->
        <mapping package="org.mendrik.suigeneris.model"/>
        <mapping class="org.mendrik.suigeneris.model.ModelObject"/>
        <mapping class="org.mendrik.suigeneris.model.Project"/>

    </session-factory>

</hibernate-configuration>


Then I have:

Code:
@Entity
@Table(name="project")
public class Project extends ModelObject {

    private static Logger log = Logger.getLogger(Project.class.getName());

    public Project() {
      //  data = new HashSet<Data>();
    }

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

    /*
    private Set<Data> data;

    public Set<Data> getData() {
        return data;
    }
    */


    public static final Dao<Project> DAO = new Dao<Project>(Project.class);

    public Dao<? extends ModelObject> getDao() {
        return DAO;
    }

}


and

Code:
@MappedSuperclass
public abstract class ModelObject {

    @EmbeddedId @GeneratedValue(strategy= GenerationType.IDENTITY)
    private Long id;
    public Long getId() {return id;}
    public void setId(Long id) {this.id = id;}

    public abstract Dao<? extends ModelObject> getDao();

}



Now trying:

Code:
<%
    Project p = new Project();
    p.getDao().save(p);
%>


gives me a frustrating:

org.hibernate.MappingException: Unknown entity: org.mendrik.suigeneris.model.Project
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:513)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1321)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:180)
at org.hibernate.event.def.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:460)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:84)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:531)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:523)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:519)
at org.mendrik.suigeneris.persistence.Dao$1.execute(Dao.java:26)
at org.mendrik.suigeneris.persistence.Transaction.run(Transaction.java:28)
at org.mendrik.suigeneris.persistence.Dao.save(Dao.java:24)


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.