Matt Gaunt

Ranch Hand
+ Follow
since Sep 05, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Matt Gaunt

Recently I have been working on a multi-page form (wizard) for internet users. One of the requirements is the necessity to save data already entered within the form so that a user can come back to it later. Is there a way to submit the data and ensure it is not validated when the save button is hit? In essence, I would like the validation phase skipped when selecting the save button but not skipped when the Submit button is selected?

Regards

Matt
15 years ago
JSF
Have you tried request.getRemoteAddr()

This will work assuming your end user is not going through a proxy. And if they are connecting via a proxy server, then that proxy server should not be stripping the remote ip address from the request object.

Obtaining the ip address is not simple using the j2ee request object as the availability of that information depends on the proxy server which redirects the end users request.

Regards

Matt Gaunt
16 years ago
JSP
Hi Riyad,

I have been leading a big change in our development strategies at my work place using MyEclipse as the tool to go forward. I notice the latest MyEclipse bundle comes with a Maven plugin. This is extremely handy for us as Maven is a tool we are utilising.

However, we need the ability to be able to import previously written projects into our workspace and then apply the appropriate capabilities. With the current Maven plugin bundled with MyEclipse, this is not possible. Will this be possible in the future.

Also, should I have an application which is already written utilising maven. Once imported into the workspace, when I add capabilities, will it be possible to add the required jars to the pom dependency list (if they don't already exist) rather than rely on the eclipse classpath where they are added at the moment.

Regards

Matt Gaunt
[ August 18, 2008: Message edited by: Matt Gaunt ]
No worries. I'm glad you sorted it out and is all working now.

Regards

Matt Gaunt
Hi Bobby,

A java application, once written and tested can be run on both a UNIX and Windows operating system. You do not have to alter the code for it to work for different environments.

Regards

Matt Gaunt
16 years ago
This seems to me like an odd question. You say you are retrieving the object in the first instance from a select statement. Now if you are retrieving a full object, that object should have an ID (otherwise known as a primary key). So if you are to delete that from the table, then only the one row should be deleted.

I would question why you have a table which does not have a primary key and seriously consider the use of a surrogate key if you don't currently have a primary key.

Could you please post the table DDL and the associated annotated object (or hibernate mapping file if that is what you are using)?

Regards

Matt Gaunt
I think I see the problem. The code should read



The value for the join column should be the foreign key field in the joined table.

In your case, you have an Order table which can have many OrderLine items. In your OrderLine table, you have a foreign key back to the Order table. The foreign key field is called ord_id. It is this field which should be put as the value of the name attribute for the @JoinColumn annotation.

Regards

Matt Gaunt
Hi Rahul,

Could you please include your Order class as well as the DDL for your Order table?

Regards

Matt Gaunt
I wouldn't say a DAO layer with Hibernate is of great usefulness. What I would say is that a DAO layer is of great value.

Personally, I wouldn't create an application without the DAO layer as it abstracts any sort of persistence framework out of the logic in your application. The DAO can be altered in any manner, using different frameworks as and when required. You can swap DAO layers in and out of your application.

Let's say for instance you have a database with a Person table. Using IDE wizards, you can create hibernate objects, annotations, mapping files etc. There would be a hibernate Person object. Now as soon as your logic code starts making calls using the hibernate sessions to save and retrieve those Person objects, you have tied your application to Hibernate. What if hibernate ends up being deprecated and becoming fully incorporated into the EJB3 container. It means there would be no further support or maintenance of hibernate. In order to alter your code, you need to go through all of your logic and change all of your hibernate calls.

If you had a DAO layer in between your hibernate objects, and it is the DAO layer using the hibernate sessions, then your logic layer is completely protected from any ORM framework. You can create a completely new DAO layer if you wish, using something other than hibernate. And if you are coding properly, your DAO classes should be implementing interfaces, such that your logic code only knows about interfaces. And if you are incorporating Hibernate with Spring, then it is easier again to alter and inject new DAO classes into your logic code.

Regards

Matt Gaunt
[ June 03, 2008: Message edited by: Matt Gaunt ]
The DAO framework allows a further layer of abstraction. Say for instance that one day, your boss walks up to your desk and says that hibernate is to be used no longer and you must go ahead and use a different framework.

Now if you have all the hibernate framework code embedded within your logic, you need to go through and pull apart all of that code and refactor it to use a new framework.

With your DAO layer, you can create a new DAO layer alongside the current one, and after you have tested it using your new framework, you should be able to pull out the current DAO layer using hibernate and put in your new DAO layer using your new framework. And you could do this without touching any of your previously heavily tested and optimised logic code.

Regards

Matt Gaunt


And I think there are two types of mappings
one to one - one employee works in only one department
one to many - one department has many employees.



I think you will find the relationship for employee to department should be many-to-one. For many employees may work in one department. Your one-to-one relationship indicates that only one employee works in one department (in other words, each department has only one employee)
Hi Rahul,

First I would look at the relationship you have there. You have a situation where an Order can have 0 to many OrderItems. So obviously, you would like to see the OrderItems belonging to an order.

Does the same hold true for an OrderItem. When you have an OrderItem object, do you need to know the Order to which it belongs. As in, is there ever going to be a time when you have an OrderItem first and need to find the Order from which it came. I would suggest that this is unlikely.

The annotations, I tend to put above the declaration of the fields as I find it much easier to read as well. But that is a personal preference.

Here is a way you should be able to achieve what you are chasing:
In the Order class you would have as follows:



And in your OrderLineItem class, I wouldn't make any reference to your Order class as you should not have a situation by where you need to find the Order to which an OrderLineItem belongs. This is information you should always have as it should be the Order you retrieve/create first.

Note, I have suggested a lazy loading of the OrderLineItems. This means that if you read the Order from the database, the OrderLineItems will not be read unless you initialise the orderItemList before closing the selection transaction. A simple order.getOrderItemList().size(); is enough to initialise it.

Hope this helps.

Regards

Matt Gaunt
Hi Cameron,

I have used Hibernate quite extensively and am a huge advocate of the annotations approach although I have come across situations where the mapping files were preferred in order to use the same POJO objects in slightly different manners for inserting as opposed to reading records.

Does your book cover users of hibernate at all levels. I would consider myself a more advanced user than someone just starting out.

Further to this, one of the issues I have had in the work place is trying to convince others hibernate is a good tool to use. Many discussions about the loss of executing direct SQL when required and overriding hibernate standard select queries abound. It is very frustrating trying to convince these people that all these things can still be achieved within the hibernate framework. Does your book give any direct reference to the convincing of sceptics and show them they can still do their direct calls within the hibernate framework while other developers can use the advantageous hibernate tools?

Regards

Matt Gaunt
Hi Bal,

This sounds a little odd. If you have a <many-to-one> relationship within the child table, this would indicate that the parent table could have many children, and thus the relationship between the parent and the child should then be <one-to-many>.

Might be best if you could show us your mapping files. Or if you are not using mapping files, show us the two classes with the associated annotations.

Regards

Matt Gaunt
Hi Adam,

I was wondering if you have an idea as to what is causing the error I have explained above please?

Regards

Matt Gaunt