First I have to tell you concerning the mapping I used the wrong word the dependencies in the mapping are not recursive bur circular.

Am 04.05.2014 22:24, schrieb mscoon:
I'm not sure I see something wrong in your code, but then again you have
omitted a lot of stuff which could be cruicial.

Does nachweiseform have any components that show/update kunde?
Label nachkundnr=new Label("kunde.id");
 add(nachkundnr);
What exactly do you mean by saying "after save it disappears"? Has it been
stored correctly in the database or is it wrong there too?
Everything is stored correctly in the Database only NachKundNr is NULL
Have you tried to create a minimal case where you are setting kunde to an
object without having any wicket forms?
I have no problems with kunde in the TestCases
What is the value of kunde before saving to the db? If it is correctly set
then you likely have a problem with your mapping. If it's not correctly set
then something is wrong with your form.
The problem is only with new Kunde() because Kunde must be preset and cannot be changed in the Form. Before using AbstractEntityModel I took all Ids of the MANYTOONE relationships in the model and loaded them from the Database and implanted them newly in Kunde before storing. My hope was to avoid this by using AbstractEntityModel.This works for all Dependencies which are set in the Form


On Sun, May 4, 2014 at 1:02 PM, Yahoo <hansheinrichbr...@yahoo.de> wrote:

I have a suspicion: I have defened all dependencies with jpa or hibernate
annotation.
So I have also a lot of cicular dependencies, which sometimes make problem.
I will give you 2 examples. one which is OK when I use AbstractEntityModel
and on which makes problem, which is not set in the form through the Model
but before.

1.

the hibernatemodel:

@IndexedEmbedded
@ManyToOne(cascade=CascadeType.MERGE,fetch = FetchType.LAZY)
@JoinColumn(name="NachAngNr",insertable=false, updatable=false)

public Angebot getAngebot(){
        return this.angebot;
     }

recursive part in Angebot:

@XmlTransient
@OneToMany(cascade={CascadeType.ALL},fetch=FetchType.LAZY)
@JoinColumn(name="NachAngNr",nullable=false )
public List<Nachweise> getNachweise() {
     return nachweise;
}

Angebot is set by DropDownChoice in the form

   private    IModel<List<? extends Angebot>> makeChoicesAngebote = new
AbstractReadOnlyModel<List<? extends Angebot>>()
              {
                  @Override
                  public List<Angebot> getObject()
                  { List<Angebot> angebotelist=new ArrayList<Angebot>();
                      Iterator angeboteiterator=
angebotManager.getAngebote().iterator();
                  while(angeboteiterator.hasNext()){
                      Angebot angebot=(Angebot)angeboteiterator.next();
if(angebot.getAngstatus().getId().longValue()==1)
                      angebotelist.add(angebot);
                  }
                      return angebotelist;
                  }

              };
                 IChoiceRenderer<Angebot> angebotchoicerenderer=
      new IChoiceRenderer<Angebot>() {

                    public Object getDisplayValue(Angebot angebot)
                      {
                          return angebot.getId();
                      }

                      public String getIdValue(Angebot angebot,int index)
                      {
                          return angebot.getId();
                      }
          };

final DropDownChoice<Angebot> angebote = new DropDownChoice<Angebot>("
angebot",
  makeChoicesAngebote,angebotchoicerenderer);


The recursive part is treated in NachweiseManagerImpl :

public Nachweise saveNachweise(Nachweise nachweise) throws
NachweiseExistsException {

       try {
           if(nachweise.getId()==null){
               System.err.println("xxxxxxxxxxxxxxxxxx Id=null");

               if(nachweise.getMitarbeiter()!=null) {
                 }
                   =======================   recursive Part  for Kunde
later =======================
    /*         if(nachweise.getKunde()!=null) {
                     System.err.println("xxxxxxxxxxxxxxxxxx Kunde");
(nachweise.getKunde()).addNachweis(nachweise);
                 }*/
                 if(nachweise.getXtyp()!=null) {
                 }

                     if(nachweise.getAngebot()!=null) {
nachweise.getAngebot().addNachweis(nachweise);
                 System.err.println("xxxxxxxxxxxxxxxxxx Angebot");
                     }
   =======================   recursive Part  for Angebot
=======================
                     if(nachweise.getAngebot1()!=null) {
nachweise.getAngebot1().addNachweis1(nachweise);
                     }

                     if(nachweise.getAngebot2()!=null) {
                     nachweise.getAngebot2().addNachweis2(nachweise);
                     }


                     if(nachweise.getObjekt()!=null) {
nachweise.getObjekt().addNachweise(nachweise);
                     }

                     if(nachweise.getPerson()!=null) {
nachweise.getPerson().addNachweis(nachweise);
                     }
           }
           return nachweiseDao.saveNachweise(nachweise);
       } catch (DataIntegrityViolationException e) {
           //e.printStackTrace();
           log.warn(e.getMessage());
           throw new NachweiseExistsException("Nachweise '" +
nachweise.getId() + "' already exists!");
       } catch (JpaSystemException e) { // needed for JPA
           //e.printStackTrace();
           log.warn(e.getMessage());
           throw new NachweiseExistsException("Nachweise '" +
nachweise.getId() + "' already exists!");
       }
   }

Angebot is set by the DropDownChoice Nachweise is first inserted and can
be changed.

2.

the hibernateModel:

//@XmlTransient
@ManyToOne(cascade = CascadeType.MERGE,fetch=FetchType.LAZY)
@JoinColumn(name="NachKundNr",insertable=false, updatable=false)
     public Kunde getKunde(){
        return this.kunde;
     }

recursive Part for Kunde


@XmlTransient
@OneToMany(cascade={CascadeType.MERGE},fetch=FetchType.LAZY)
@JoinColumn(name="NachKundNr",insertable=false, updatable=false )
public List<Nachweise> getNachweise() {
     return nachweise;
}

Kunde ist set  is set after before adding the form :

  final NachweiseForm nachweiseform=new NachweiseForm("form",model);

     if 
(!(pars.getPosition("nachweisnr")>=0&&pars.get("nachweisnr").toLong()>0))
{

     if (pars.getPosition("kundennr")>=0&&pars.get("kundennr").toLong()>0)
{
         Kunde kunde=kundeManager.get(new Long(pars.get("kundennr").
toString()));
         System.err.println("====================== set Kunde reached");
         nachweiseform.getModelObject().setKunde(kunde);
=======================   recursive Part  for Kunde early set
=======================
nachweiseform.getModelObject().getKunde().addNachweis(
nachweiseform.getModelObject());
     }

     }

     after opening the form you see the Id of Kunde
after save it disappears.

     add(nachweiseform);

When I set the recursive part later same result

When I try to set the recursive part later I get the same result

Am 04.05.2014 08:55, schrieb mscoon:

  Usually this is not a problem. But maybe you are doing something different
that the "usual". I think you will need to show us your code to help you
any further.


On Sun, May 4, 2014 at 9:12 AM, Yahoo <hansheinrichbr...@yahoo.de> wrote:

  It's the solution for all MANYTOONE-Fields defined in the Form
I have a MANYTOONE-Field which is preset and not set in the Form.
This field is not stored.

Am 02.05.2014 01:24, schrieb mscoon:

   No you don't. The referenced objects will be serialized along with the

entity you are serializing and everything should work just fine.




On Thu, May 1, 2014 at 10:30 PM, Yahoo <hansheinrichbr...@yahoo.de>
wrote:

   Ok,thank  you, that's it.

My Entity has a lot of MANYTOONE relationships which are set
byDropDownChoices.
In the case of a new entity, do I have to load all these Entities too
and
to save their ids ?


Am 01.05.2014 15:01, schrieb mscoon:

    Heiner,

  You didn't tell us which dependency injection framework you  you
using.

If you're using Spring then simply use the @SpringBean annotation to
get a
reference to an EntityManager or a Dao.

@SpringBean automatically works only for components so you'll also
need
to
add a call to injector to your model's constructor.

public class MyModel implements IModel {

      @SpringBean
      EntityManager entityManager;

      public MyModel() {
        Injector.get().inject(this);
      }

...
}

This will take care of instantiating all @SpringBean annotated fields
as
well are handle their serialization/deserialization.

Marios



On Thu, May 1, 2014 at 3:42 PM, Yahoo <hansheinrichbr...@yahoo.de>
wrote:

    I tried the AbstractEntityModel <http://http://wicketinaction.

  com/2008/09/building-a-smart-entitymodel/> from Igor Vaynberg but I
didn't get
solved the @Dependency annotation from Vaynbergs salve.
Is there another solution for the Hibernate integration for models.

Best regards
Heiner



   ------------------------------------------------------------
---------

To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



  ---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to