File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Spring and the fly likes Bind a whole class in jsp? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Bind a whole class in jsp?" Watch "Bind a whole class in jsp?" New topic

Bind a whole class in jsp?

Bradusca Luisa

Joined: Oct 28, 2009
Posts: 6
Hi, I use spring web flow 2 with hibernate annotations. I have a question that may sound stupid but I have to ask it: is there possible that in my jsp using form tags to bind a whole class? I am asking this, because when I generated my entity classes from SQL Server 2008 using Intellij it autogenerated also my @ManyToOne column (it's about 2 tables: one named Leader-with idLeader,name..and so on and another named Phd in wich i have idLeader refered. When I generated my tables with hibernate annotations, in my Phd class intellij put also my @ManyToOne columnm (PhdEntity has now beside the idLeader property, another one refering to Leader class with getter and setter). All was good until I tried to run my application and gaved me the error that i must put insertable = false, updatable = false at idLeader column. Having that done, my application worked perfectly until I had to insert the referenced column idLeader wich doesn't work because I have the insertable = false, updatable = false. In that case it is rationable to insert the class Leader instead of the id(beacause I have the column generated). So in my jsp i have all the ${leaders} in a form:select with the path='Leader' but I can't fix this because it gives me the error that it can't bind String to Leader.class (even if i add a PropertyEditorRegistrar: propertyEditorRegistry.registerCustomEditor(Leader Entity.class,new ClassEditor());
It is possible to bind a whole Leader.class or I have to delete that autogenerated column and let only my idLeader in PhdEntity class?
Thanks in advanced
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Towards the Hibernate first part.

The reason why you needed the insertable/updatable to false is because the FK id would be mapped twice in your class. So now in Java code you must make sure you set both object properties.

So if you have

both of those are the FK to the parent table. So if you didn't have insertable/updatablse = false on one of them update and insert statements to the child table would have parent_id field in there twice like

insert into child fields(parent_id, parent_id) values (?, ?)

so if you have

@Column(insertable = false, updatable=false)
private Parent parent;

and you only set the parent attribute and not the parentId attribute it will never populate the parent_id field in the child table.

I used annotations for Hibernate to make it simple to post rather than xml mapping.


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Bradusca Luisa

Joined: Oct 28, 2009
Posts: 6
Thanks for your reply! For the Child class I have:

private Parent parent;

@JoinColumn(name = "parentId", referencedColumnName = "parentID")
public Parent getParentByParentId(){...}

public void setParentByParentId(Parent parent){...}

private int parentId;

@Column(name = "parentId", length = 10,insertable = false, updatable = false)
public int getParentId(){..}

public void setParentId(){..}

So, I have the insertable = false, updatable = false to the parentId column. And how do I insert a Parent then(it will be with the setParentByParentId?)<-because in this case I don't know if it is possible to bind a whole class from the jsp(I don't want in the web flow to make a new search for Parent with it's id when I have already done a search for all)
I agree. Here's the link:
subject: Bind a whole class in jsp?
It's not a secret anymore!