Hi,

Not sure if this isn't more of a Hibernate question rather than an Appfuse one, but I'm going to give it a try anyway.

I defined two POJOs, Model and Module. (I know, those names are a bug waiting to happen...) There exists a many-to-many relationship between them, so, following the Hibernate Annotations Reference Guide, I coded my Model.java like this:

@Entity
@Table(name = "model")
public class Model extends BaseObject implements Serializable {
...
        private Long id;
...
        private Set<Module> modules = new HashSet<Module>();
...
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        public Long getId() {
                return id;
        }
...
        @ManyToMany(fetch = FetchType.EAGER)
        @JoinTable(
                name="model_module",
                joinColumns = { @JoinColumn( name="model_id") },
                inverseJoinColumns = @JoinColumn( name="module_id")
        )
        public Set<Module> getModules() {
                return modules;
        }
...
}

My Module.java looks like this:

@Entity
@Table(name = "module")
public class Module extends BaseObject implements Serializable {
...
        private Long id;
...
        private Set<Model> models = new HashSet<Model>();
...
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        public Long getId() {
                return id;
        }
...
        @ManyToMany(
                mappedBy = "modules"
        )
        public Set<Model> getModels() {
                return models;
        }
...
}

I used mvn appfuse:gen on both entities to generate CRUD; no problems there. The framework generated sample data for the model and module tables, and I manually added the following data for the join table:

    <table name="model_module">
        <column>model_id</column>
        <column>module_id</column>
    <row>
        <value description="model_id">-1</value>
        <value description="module_id">-1</value>
    </row>
    <row>
        <value description="model_id">-1</value>
        <value description="module_id">-2</value>
    </row>
    <row>
        <value description="model_id">-1</value>
        <value description="module_id">-3</value>
    </row>
    <row>
        <value description="model_id">-2</value>
        <value description="module_id">-2</value>
    </row>
    <row>
        <value description="model_id">-3</value>
        <value description="module_id">-3</value>
    </row>
    </table>

So model -1 has 3 modules and both model -2 and model -3 have only 1 module.

Now if I run mvn jetty:run-war and browse the list of models, the table shows 5 models, three of which having id = -1. Somehow, I seem to be getting a full join as a result. I guess I must have made a mistake in my Hibernate annotations, but I can't see what could be wrong. Any suggestions?

Thanks,

Ger-Jan



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to