• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Bind a whole class in jsp?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Mark
 
Bradusca Luisa
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply! For the Child class I have:

private Parent parent;

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

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

private int parentId;

@Basic
@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)
reply
    Bookmark Topic Watch Topic
  • New Topic