aspose file tools*
The moose likes Object Relational Mapping and the fly likes Using Hiberntate: adding new data to derby db from JSP form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Using Hiberntate: adding new data to derby db from JSP form" Watch "Using Hiberntate: adding new data to derby db from JSP form" New topic
Author

Using Hiberntate: adding new data to derby db from JSP form

Jason Flaherty
Greenhorn

Joined: Sep 23, 2011
Posts: 15

Hi all, I have been reading up on this forum for a while, but now have a question I cannot find the answer for here. I might be searching wrong, so if someone has a thread recommendation, please post it.

I am new to java really. I have a simple timesheet application that uses a derby db, struts and hibernate and adds fields userCn, userName, firstName,lastName... etc... I am trying to use a JSP page to populate the data with a new user. I have a method called lookup:



...that takes data from a jsp input form and loads a new page with the persons CN. I have been trying to create a page that adds a new user with a method called create() that looks like this:



I feel like I should be using set instead of get in there... but set won't work without errors. I am confused on how this works. How come I can get data from my form no problem with the lookup, but cannot add it?

Thanks for any ideas.


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61206
    
  66

First principles: if you are coupling your form to the model code, your coupling is too close. Your data layer should have no knowledge of the front end -- and that includes the whole concept of a form. Rather, in the controller layer you should be populating an entity class with the information from the form and passing that to the model layer.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jason Flaherty
Greenhorn

Joined: Sep 23, 2011
Posts: 15

Hi, thanks for the reply. I don't entirely know what you said there, but I think you are saying my program knows to much about the users?

My lookup method is ok though correct? it is located outside of the file that contains the main if that makes any difference.

thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61206
    
  66

Jason Flaherty wrote: it is located outside of the file that contains the main if that makes any difference.

OK, now I'm really confused. Is this a web application or not?

If it's a web application, it doesn't have a main() entry point!
Jason Flaherty
Greenhorn

Joined: Sep 23, 2011
Posts: 15

Yes, its a jsp app. I was using a main to populate the db to test it was working.

Where my issue is, is adding / creating a user. I am not sure why I am not getting data from the form.

Thanks again,

Greenhorn.
Jason Flaherty
Greenhorn

Joined: Sep 23, 2011
Posts: 15

Here is my class if that will help:
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61206
    
  66

OK, please avoid such red herrings in the future.

In any case, it sounds like you are passing a form to your model layer. Is this the case? If so, it's a violation of the principles of Separation of Concerns that govern the MVC pattern. The model should be completely agnostic of the controller and presentation layers.

If you haven't read then yet, I always suggest JSP writers read these articles:
  • The Secret Life of JSPs
  • The Front Man

  • Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61206
        
      66

    I'm not a big fan of using a set() to set a user and then calling create() on it. Why aren't you just passing the user to the create method?
    Jason Flaherty
    Greenhorn

    Joined: Sep 23, 2011
    Posts: 15

    Bear Bibeault wrote:I'm not a big fan of using a set() to set a user and then calling create() on it. Why aren't you just passing the user to the create method?


    Hi Bear, do I not have to create the create() method? Is this build in? I cannot find it in any of my hibernate code and all i see in my books is URI create().

    I'll keep looking. Thanks for the reads also, I'll read em right now!
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61206
        
      66

    I didn't say anything about removing create(), just that I'm not a fan of the the style where you have to set the user before calling create(), rather than just passing the user to the create() method directly.

    In any case, this really isn't about JSP, so I've moved it to the ORM forum.

    I'm not sure what book and patterns you are following but this isn't similar to anything I've actually seen in use.
    Jason Flaherty
    Greenhorn

    Joined: Sep 23, 2011
    Posts: 15

    Bear Bibeault wrote:just that I'm not a fan of the the style where you have to set the user before calling create(), rather than just passing the user to the create() method directly.


    So you don't need to have Setters and Getters all of the time then I am hearing?

    Thanks again.

    btw... you can let me know if I am asking irrelevant questions... I might be going down the wrong path here

     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Using Hiberntate: adding new data to derby db from JSP form