If I include the folowing lines :
if(NachweiseForm.this.getModelObject().getKunde()!=null) {
Kunde kunde =
kundeManager.get(NachweiseForm.this.getModelObject().getKunde().getId());
NachweiseForm.this.getModelObject().setKunde(kunde);
kunde.addNachweis(NachweiseForm.this.getModelObject());
System.err.println("Kunde");
}
before the save
everything is fine
But I hoped to avoid such lines by AbstractEntityModel.
Because nowI have to load Kunde twice: First when I prepare the new
Nachweise() before calling the form
and then when I save Nachweise when I submit the Form.
My idea was to implant Kunde through the form.
But how could you do it only by a Label.
Am 05.05.2014 20:40, schrieb mscoon:
Actually what I said below is wrong because this line is after the line
that throws the exception. But my explanation still holds. Something before
the line that is throwing the exception is causing an object with a
reference to a new Nachweise
to be saved while the Nachweise is still unsaved. You need to search at
what is happening before the line with the exception, maybe even before the
page is created.
Now, a wild guess (I may well be wrong) is that the following line:
nachweiseform.getModelObject().getKunde().addNachweis(nachwe
iseform.getModelObject());
may be causing the problem if hibernate tries to save kunde with
nachweiseform.getModelObject()
which is a new object with a null id.
You may try to move this line to saveNachweise().
On Mon, May 5, 2014 at 2:54 PM, Yahoo <hansheinrichbr...@yahoo.de> wrote:
Am 05.05.2014 11:05, schrieb mscoon:
In a previous message you sent the following snippets:
//@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 )
when I remove this I get the error :
org.hibernate.TransientObjectException: object references an unsaved
transient instance - save the transient instance before flushing:
braunimmobilien.model.Nachweise
at org.hibernate.engine.internal.ForeignKeys.
getEntityIdentifierIfNotUnsaved(ForeignKeys.java:249)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:459)
at org.hibernate.type.ManyToOneType.nullSafeSet(
ManyToOneType.java:132)
at org.hibernate.persister.collection.AbstractCollectionPersister.
writeElement(AbstractCollectionPersister.java:867)
at org.hibernate.persister.collection.AbstractCollectionPersister.
insertRows(AbstractCollectionPersister.java:1475)
at org.hibernate.action.internal.CollectionUpdateAction.execute(
CollectionUpdateAction.java:86)
at org.hibernate.engine.spi.ActionQueue.execute(
ActionQueue.java:362)
at org.hibernate.engine.spi.ActionQueue.executeActions(
ActionQueue.java:354)
at org.hibernate.engine.spi.ActionQueue.executeActions(
ActionQueue.java:278)
at org.hibernate.event.internal.AbstractFlushingEventListener.
performExecutions(AbstractFlushingEventListener.java:326)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(
DefaultFlushEventListener.java:52)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1213)
at org.hibernate.internal.SessionImpl.managedFlush(
SessionImpl.java:402)
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.
beforeTransactionCommit(JdbcTransaction.java:101)
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.
commit(AbstractTransactionImpl.java:175)
at org.springframework.orm.hibernate4.HibernateTransactionManager.
doCommit(HibernateTransactionManager.java:554)
at org.springframework.transaction.support.
AbstractPlatformTransactionManager.processCommit(
AbstractPlatformTransactionManager.java:755)
at org.springframework.transaction.support.
AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionMan
ager.java:724)
at org.springframework.transaction.interceptor.
TransactionAspectSupport.commitTransactionAfterReturnin
g(TransactionAspectSupport.java:475)
at org.springframework.transaction.interceptor.
TransactionAspectSupport.invokeWithinTransaction(
TransactionAspectSupport.java:270)
at org.springframework.transaction.interceptor.
TransactionInterceptor.invoke(TransactionInterceptor.java:94)
at org.springframework.aop.framework.ReflectiveMethodInvocation.
proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.
invoke(ExposeInvocationInterceptor.java:91)
at org.springframework.aop.framework.ReflectiveMethodInvocation.
proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.
invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy112.get(Unknown Source)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.wicket.proxy.LazyInitProxyFactory$JdkHandler.invoke(
LazyInitProxyFactory.java:435)
at com.sun.proxy.$Proxy94.get(Unknown Source)
at braunimmobilien.webapp.nachweis.NachweisPanel.<init>(
NachweisPanel.java:100)
at braunimmobilien.webapp.nachweis.NachweisPage.<init>(
NachweisPage.java:47)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.apache.wicket.session.DefaultPageFactory.newPage(
DefaultPageFactory.java:171)
at org.apache.wicket.session.DefaultPageFactory.newPage(
DefaultPageFactory.java:99)
at org.apache.wicket.DefaultMapperContext.newPageInstance(
DefaultMapperContext.java:137)
at org.apache.wicket.core.request.handler.PageProvider.
resolvePageInstance(PageProvider.java:268)
at org.apache.wicket.core.request.handler.PageProvider.
getPageInstance(PageProvider.java:166)
at org.apache.wicket.request.handler.render.PageRenderer.
getPage(PageRenderer.java:78)
at org.apache.wicket.request.handler.render.WebPageRenderer.respond(
WebPageRenderer.java:271)
at org.apache.wicket.core.request.handler.RenderPageRequestHandler.
respond(RenderPageRequestHandler.java:175)
at org.apache.wicket.request.cycle.RequestCycle$
HandlerExecutor.respond(RequestCycle.java:862)
at org.apache.wicket.request.RequestHandlerStack.execute(
RequestHandlerStack.java:64)
at org.apache.wicket.request.cycle.RequestCycle.execute(
RequestCycle.java:261)
at org.apache.wicket.request.cycle.RequestCycle.
processRequest(RequestCycle.java:218)
at org.apache.wicket.request.cycle.RequestCycle.
processRequestAndDetach(RequestCycle.java:289)
at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(
WicketFilter.java:259)
at org.apache.wicket.protocol.http.WicketFilter.
processRequest(WicketFilter.java:201)
at org.apache.wicket.protocol.http.WicketFilter.doFilter(
WicketFilter.java:282)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.
doFilter(ServletHandler.java:1338)
at com.opensymphony.sitemesh.webapp.SiteMeshFilter.
doFilter(SiteMeshFilter.java:65)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.
doFilter(ServletHandler.java:1338)
at org.springframework.orm.hibernate4.support.
OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:
152)
at org.springframework.web.filter.OncePerRequestFilter.
doFilter(OncePerRequestFilter.java:107)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.
doFilter(ServletHandler.java:1338)
at braunimmobilien.webapp.MessageFilter.doFilter(
MessageFilter.java:32)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.
doFilter(ServletHandler.java:1338)
at org.springframework.web.filter.CharacterEncodingFilter.
doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.
doFilter(OncePerRequestFilter.java:107)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.
doFilter(ServletHandler.java:1338)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(
ServletHandler.java:484)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(
ScopedHandler.java:119)
at org.eclipse.jetty.security.SecurityHandler.handle(
SecurityHandler.java:524)
at org.eclipse.jetty.server.session.SessionHandler.
doHandle(SessionHandler.java:233)
at org.eclipse.jetty.server.handler.ContextHandler.
doHandle(ContextHandler.java:1065)
at org.eclipse.jetty.servlet.ServletHandler.doScope(
ServletHandler.java:413)
at org.eclipse.jetty.server.session.SessionHandler.
doScope(SessionHandler.java:192)
at org.eclipse.jetty.server.handler.ContextHandler.
doScope(ContextHandler.java:999)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(
ScopedHandler.java:117)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(
ContextHandlerCollection.java:250)
at org.eclipse.jetty.server.handler.HandlerCollection.
handle(HandlerCollection.java:149)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(
HandlerWrapper.java:111)
at org.eclipse.jetty.server.Server.handle(Server.java:350)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(
AbstractHttpConnection.java:454)
at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(
AbstractHttpConnection.java:890)
at org.eclipse.jetty.server.AbstractHttpConnection$
RequestHandler.headerComplete(AbstractHttpConnection.java:944)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:630)
at org.eclipse.jetty.http.HttpParser.parseAvailable(
HttpParser.java:230)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(
AsyncHttpConnection.java:77)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(
SelectChannelEndPoint.java:606)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(
SelectChannelEndPoint.java:46)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(
QueuedThreadPool.java:603)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(
QueuedThreadPool.java:538)
at java.lang.Thread.run(Thread.java:744)
at
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)
{
here ===> Kunde kunde=kundeManager.get(new
Long(pars.get("kundennr").toString()));
System.err.println("====================== set Kunde reached");
nachweiseform.getModelObject().setKunde(kunde);
// nachweiseform.getModelObject().getKunde().addNachweis(
nachweiseform.getModelObject());
}
}
add(nachweiseform);
public List<Nachweise> getNachweise() {
return nachweise;
}
It seems like both sides of the relationship are set as insertable=false,
updatable = false. This would explain why kunde becomes null after
saving,
though it contradicts your statement that everything is saved ok in the
db.
Either way the AbstractEntityModel has nothing to do with how properties
of
the model object are stored in the db, so I still believe the problem is
somewhere else in your code.
Marios
On Mon, May 5, 2014 at 11:26 AM, Yahoo <hansheinrichbr...@yahoo.de>
wrote:
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
---------------------------------------------------------------------
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