3 Replies Latest reply on Oct 19, 2009 11:53 AM by Nicklas Karlsson

    Wiring components together in an EntityQuery class

    Yann Lambret Newbie


      I can't figure out how to wire components in an EnityQuery class. I've got the following entity:

      @Table(name = "bottle")
      public class Bottle implements Serializable {
           private static final long serialVersionUID = ...
           private Appellation appellation;
           private Wine wine;

      Appellation and Wine classes are both entities too.

      The EntityQuery component looks like this:

      public class BottleList extends EntityQuery<Bottle> {
           private static final long serialVersionUID = ...
           private static final String EJBQL = "select b from Bottle b " +
           "join fetch b.appellation a " +
           "join fetch b.wine w";
           private static final String[] RESTRICTIONS = {
                "lower(a.name) like lower(concat(#{bottleList.bottle.appellation.name},'%'))",
                "lower(w.name) like lower(concat(#{bottleList.bottle.wine.name},'%'))",
                "b.year like concat(#{bottleList.bottle.year},'%')",};
           private Bottle bottle = new Bottle();

      As you can see, this is pretty much the code generated by seam-gen except for the query which loads eagerly dependent entities.

      The code above doesn't work because Appellation and Wine objects are not initialized. I can make in work by doing this, as detailed in seam documentation:


      <component name="bottleListAppellation" class="net.wait4it.bottles.model.Appellation" />
      <component name="bottleListWine" class="net.wait4it.bottles.model.Wine" />
      <component name="bottleListBottle" class="net.wait4it.bottles.model.Bottle">
           <property name="appellation">#{bottleListAppellation}</property>
           <property name="wine">#{bottleListWine}</property>

      and by changing the EntityQuery class like this:

           private Bottle bottle;

      Could you please tell me what's the proper way to do the same in plain old java ? Because I've tried to create dependencies in my EntityQuery and to use appropriate setters, but it doesn't work - at all.

      Thanks a lot