Win a copy of Spring Boot in Practice this week in the Spring forum!

Marcus Hathaway

Ranch Hand
+ Follow
since Jun 07, 2005
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Marcus Hathaway

Hi Ranchers,

For several reasons as indicated here: http://www.hibernate.org/117.html#A36, lazy loading of remote objects is not possible with hibernate.

After much research, i have seen solutions people have come up with to solve this, such as http://h3t.sourceforge.net/. I also notice other products such as TopLink offer their own strategy to handle this (e.g. using javaagent with toplink-essentials-agent.jar).

I just wondered if anybody has any experience of this issue and how you decided to handle?

For examples sake, lets assume we have an object Order which lazy loads a collection of OrderItems. On the client (remote) site, we do a call to get the order items when needed. Using ejb3/hibernate, saying order.getOrderItems() would thrown an exception on the client (and rightly so). So what's approaches should be considered to get the order items?

Along with the solution i copied in above, of course the order items could be loaded on the server side before being returned to the client. However, let's assume we DON'T want to do this and only want to access this collection on the rare instance the order items are required (for arguments sake...).

Any experiences or points to provoke my thoughts would be greatly appreciated.

Thanks!
Hi Ranchers,

I'm looking for a way to be able to open and print an external PDF file to a named printer.

To do this so it opens and prints to a default printer you can use code like:



However, i can't seem to specify what printer it actually prints on. I've been trying with this, but it just seems to open the file and doesn't print:



Any suggestions would be greatly appreciated!

Thanks
14 years ago
Thanks Mark...i think the penny is finally starting to drop in what you are trying to say. I will investigate both Spring & EJB3, so i guess i've learnt from this post that i need something else (be it EJB3/Spring/whatever) to compliment Hibernate in achieving my goals.

Thanks for the comments.


"Currently each client app configures its own Session Factory locally, connecting to a remote database."

Which is two tier.



Absolutely correct....this is the motivation for the post to try and get some ideas on how i can move away from this USING hibernate.

I'm definatly going to start exploring and having a play with EJB3, so thanks for your comments. However, has anybody any suggestions for trying to achieve a n-tier architecture with a rich client using Hibernate? Am i flogging a dead horse with this
Hi Mark,

Thanks for the replies but i'm not sure we're on the same issue anymore. You've completey lost me suggesting Visual Basic.

I want to move AWAY from a 2-tier architecture but unsure where Hibernate should be "placed" in the application. Currently each client app configures its own Session Factory locally, connecting to a remote database. Reading around on the internet it seems many people have similar issues with multi user swing apps and essentially the handling of sessions, i guess i was seeing if anybody had any experience. I don't want to get into any kind of debate over EJB3 or Hibernate....my motivation is simply to try and learn a bit more about Hibernate and the best way to use it. My reading around on the subject also points me towards using a JBoss AS with Hibernate....i'd like to know why, and what advantages this will give me in this kind of setup. For instance, will i be able to only have to create one session factory per schema that multi users can pull a Session off etc? I'm really just after other peoples experience in how they have structured a similar app in a production envirionment. Someone may say its crazy to try and use Hibernate in such an architecture....i'm just after opinions and experiences really.

From your orginal post it sounded like you'd prefer to use EJB3 but without an explanation of why.

Personally, I would take the Swing to EJB 3 on JBoss to Back End Database architecture.

Not knowing EJB3 in any detail, i just wondered why you'd favour this approach.
[ October 12, 2007: Message edited by: Marcus Hathaway ]
Hi guys,

Thanks for the replies.

Mark....what are your reasons for suggesting EJB3 over Hibernate? I don't have any real production experience with either and have simply being learning Hibernate over the last few months...my understanding is that EJB3 and Hibernate are two of the same kind of thing (in terms of being persistence models). I'II be looking into EJB3 in more detail soon once i feel i've got a real understanding of Hibernate, its advantages and limitations.

So I guess what my question is...why would EJB3 suit this kind of architecture better than Hibernate? My motivation for the post is really to try and move away from the 2-tier architecture but unsure at present how to best achieve this (or if possible to achieve this) using Hibernate in a multi user Swing application.

A Head First Hibernate book would be brilliant...slightly off topic, i've often wondered if Head First ever plan to update Head First EJB?

Although i do like Java Persistence with Hibernate, it doesn't hit every nail on the head and i often find myself looking for answers in other places
14 years ago
Hi Ranchers,

I'm looking for some advice in how one would structure a hibernate driven swing application that can have multiple users, connecting to a database sat on a remote server away from the actual swing app. Currently, every instance of the application creates its own session factory and i have implemented my own handling of individual sessions in the swing app that currently seems to be *ok* for the multi user aspects. (I say *ok*, but am on the lookout for cleaner pattern for this).

Lets suppose i wanted to limit access to the database on the server, so that only local connections where allowed. Would this be feasible in an application like I describe?

Some ideas i have had include setting up a JBoss server on the server and configuring datasources through JNDI. I've also seen you can expose the actual SessionFactory as a resource through JNDI, although its not obvious to me how this would work in a remote swing app? I have no practical experience of using an application server like JBoss, so am unaware really of its power/limitations in this regard. I guess, this is the thrust of my post, what are the capabilities of such an approach?

Or perhaps other developers can share there own experiences of a similar scenario and give me some food for thought with a different approach?

Thanks for any advice

Marcus.
Hi ranchers,

When hibernate is initially called for the first time in my system it seems to take an age to load up.

I expect this to some extent whilst classes are mapped and other things are configured. However, i notice this lines seems to take over a minute to do:

INFO C3P0Registry:204 - Initializing c3p0-0.9.1 [built 16-January-2007 14:46:42; debug? true; trace: 10]

Anybody have any ideas on how i can speed up the performance of this or hibernate in general when it kicks in?

Thanks in advance for any tips!
Hi ranchers,

I'm facing some difficulty mapping a one-to-one relationship on a link table. I'm not entirely sure what the best way to go about this is...so any suggestions on mapping or alternative design would be most welcome.

If we imagine this scenario. Let's say we have a table Product and a table PriceFormula. These tables are completely independant of each other. However, a product MAY have a reference to a single PriceFormula (but not always). Therefore, my design would be not to have a reference in the Product table (as not all products will need it) but to introduce a third (link) table ProductPriceFormula. ProductPriceFormula would share the same primary key as Product.

So ProductPriceFormula table would have say two fields ProductID and PriceFormulaID.

In hibernate i'm thinking that ProductPriceFormula would need to be represented as an object? Is this correct? So i couldn't just put a PriceFormula object in the Product object...instead i would need to create a ProductPriceFormula object and hold a reference to that in Product?

I'm thinking my ProductPriceFormula class would look like:

class ProductPriceFormula
{
private Product product;
private PriceFormula priceFormula;

//Getters & Setters
}

Assuming all of the above makes sense...how would one then map this class in hibernate?

I'm thinking the product class mapping would have something like this in for the ProductPriceFormula:

<one-to-one name="productPriceFormula" class="ProductPriceFormula" cascade="save-update"/>

However i can't seem to get the ProductPriceFormula class mapping right

Any tips or comments would be greatly appreciated, thanks!
Hi,

This problem describes exactly the problem i am having and seem so far unable to resolve.

My email class works fine about 80% of the time...but on some smtp.hosts i get an exception:

javax.mail.AuthenticationFailedException
at javax.mail.Service.connect(Service.java:306)
at javax.mail.Service.connect(Service.java:156)

I've followed the excellent advice Paul gives above in changing the way the message is sent and this did eliminate some transport exceptions.

However i get the above exception from the line t.sendMessage(msg, msg.getAllRecipients());

Has anybody got any suggestions or pointers on this? Its been an ongoing problem of mine for ages now and i'm not sure what else to try

My code (which works on the majority of emails sent out by different hosts) is:

Any tips would be greatly appreciated!

15 years ago
Hi Paul,

Thanks for clearing that up!

Yes...i'm sorry i meant to say two attributes that make up the primary key.

That example above was pretty bad that i thought of on the spot...yes in that example i guess accountNumber could and probably should be the primary key. However i often work on database tables (that already exist and difficult to change) that have multiple columns as the primary key...so i know now that composite mapping is whats required.

Thanks again
Hi,

What's the best way to go about mapping multiple primary key columns in hibernate?

I've done some reading about composite id's but can't decide if this is what's required.

For instance, given the database table:

SupplierBankDetails accountNo, sort, supplierID)

where accountNo and sort are primary keys whilst supplierID is a forign key?

The table could be anything....the point is how would one map two columns (like accountNo and sort) as the id mapping value?

Any advice would be greatly appreciated,

Cheers!
Ok i've found a good article and solution for my inheritance questions that other learners may find useful:

http://www.developer.com/open/article.php/10930_3559931_5

I'm still looking for inspiration on the composition issue if anyone has any suggestions?

So to summarise a database table:

TyreProduct(width, rim, aspect, speed, tyreCategory, //other tyre stuff)

In java i already have a class that can represent a TyreSize (so the width, rim, aspect, speed parts).

Therefore in the POJO TyreProduct instead of having to detail width, rim, aspect i can just have an object TyreSize. How can i populate that TyreSize in my mappings?

Thanks for any suggestions