Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!

Songezo Nkukwana

Ranch Hand
+ Follow
since Nov 27, 2008
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
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 Songezo Nkukwana

Actually no, its maven dependencies packaged under common-aux.1.0.1.RELEASE.jar
8 years ago

Jesper Young wrote:That class and package is not something in the standard Java library, nor is it something from a well-known open source library. It's not a standard or well-known class.

Do you need this for a school project? Ask your teacher where to get it. Are you working at a company? Ask your colleagues or your manager where to get this.



Sorry, i just picked up its an internal class... Thanks a lot
8 years ago
Hi i'm missing jar for common.money.MonetaryAmount classes for percentages and money formats. Any idea which Jar file do i need for this?
8 years ago

Ulf Dittmer wrote:Then you need to encrypt the parameter on the server-side before sending it to the client. And if it's encrypted, then there's no problem with showing it in the URL, because the user can't make sense of it.

A better alternative to round-tripping a value to the client and back would be to store it in a server-side session, though.



Thanks, will look at these options
8 years ago

Ulf Dittmer wrote:What are you trying to protect against?



Well, the user viewing the page ... They mustn't see the passed parameter
8 years ago
Hi, would like to hide data or parameter on URL when sending using GET ... I believe the possible way is to encrypt that parameter but not sure how to. Are there any examples somewhere?
8 years ago
Hi, i have this class



Assuming map has been initialized successfully with atleast 10 objects with its managers, how do i display its contents if ClassA is accessed through its instance variable?



8 years ago
Hi, i have a Hibernate Java Application Tester which i use slf4j for my console output .... The loggers work fine but only display info within the application class. I have other classes on different packages using the same slf4j logger, but none of those are displayed ... My log4j.properties is placed under the src directory ... All my classes are situated on their respective packages and use slf4j, but only the class with main() method gets logged/display ... Any reason for that?

here's my log4j.properties



my application class



other classes not displayed ...


finding Member instance with property: does not get displayed
Hi, using hibernate mapping .. Is it possible to partially map a class to a table leaving out some table columns in the mapping xml file? And, is it possible to have more properties in the mapped class which do not exist as a column in the table?
Hi, in my struts-config file i define a form bean



this config file resides in ProjectA WEB-INF and apps.navy.profiles.actionforms.RankProfileForm points to a package in projectB and projectB doesn't have web capabilities (WEB-INF folder), all it has simply is a src folder with all the packages i need ... I get a ActionForm not found exception which means to me struts-config file does not find the ActionForm in projectB... is there a reason for this? ProjectB is a jar file in ProjectA build path ..
9 years ago
Hi. here's the error



more ...



struts-config



Not sure what seems to be the problem here??
9 years ago

Cameron Wallace McKenzie wrote:Create a filter for your struts servlet and start it before and after the struts servlet is inovked. That's the easiest way. It's known as the 'open session in view' pattern, and will work so long as your web and ejb tier are on the save layer.

Hibernate and JPA Open Session In View Pattern

Whatever you do, do NOT do it in your DAOs. That's a rookie mistake.

-Cameron McKenzie



I read this -> http://www.theserverside.com/tt/articles/article.tss?l=HibernateTomcat which seems to discourage getting sessions from thread using getCurrentSession(). It suggests that one should always open a new session ...


There is one further point we wish to make about the above servlet. Notice the following line of code near the top of the method doQuery():

Session session = HibernateUtil.getSessionFactory().openSession();

We could have chosen the following alternative syntax - but we would never choose to do so with Tomcat:

Session session = HibernateUtil.getSessionFactory().getCurrentSession();


Why would we never use this alternative syntax with Tomcat? The difference between openSession() and getCurrentSession() is that the former, each time it is used, provides a brand new Hibernate Session. That is exactly what we want in our servlet. In contrast, getCurrentSession attempts to associate a Hibernate Session with a specific thread (the Singleton-per-Thread pattern), which Hibernate achieves via the use of an embedded (hidden) ThreadLocal. Unfortunately, Tomcat maintains a thread pool, and re-uses a given thread after a particular Http request is finished with it. Hence a brand new Http request can receive a previously used thread, which already happens to have a Hibernate Session associated with it (via the ThreadLocal), and getCurrentSession() may by chance receive an unrelated Hibernate Session when it ought to receive a brand new one. We may have a new Http session, and logically a new thread, but physically be re-using an existing thread. In this way, Tomcat 5.5.x and Hibernate 3.1 can confuse each other.

We choose to bypass the issue entirely by using SessionFactory.openSession, and avoiding the use of SessionFactory.getCurrentSession in a Tomcat environment.

The conflict we described above is readily testable. Setup a Tomcat 5.5 environment allowing only a small number of concurrent threads - say 3 or 4. (You accomplish this via an entry in Tomcat Root\conf\server.xml, namely by setting the maxThreads attribute of the applicable <Connector> element in this file to 3 or 4.) Create a couple of distinct, simplistic business transactions (conversational transactions or long-running transactions) which span Http requests. Attempt to preserve information in a ThreadLocal - any information �'�it doesn�'�t need to have anything to do with Hibernate - and do some tracing/logging in which you display the thread ID. You will see Tomcat thread pooling eventually recycle thread IDs to another business transaction, allowing inappropriate access to the ThreadLocal contents to take place.



Isn't Filter's or Interceptor Servlets exists to help achieve lazy loading?
Hi, working on a struts-web application using hibernate persistence tool. Since we using tomcat, my colleague suggest that we should avoid JTATransaction management and use default JDBCTransaction. We both a re new to hibernate and not sure where to demarcate out code with transactions. I have DAOs and service classes, then action classes. We plan to use the Hibernate session-per-request pattern with threadLocal configured with a context (can't say i understand much of that) i.e this ..

is configured within hibernate config file. My question is where exactly should the code session.beginTransaction() go? Here's my service class


I tried these two methods




Both seem to work, which one is recommended? Would they work for lazy-initialization/loading?
In fact Paul, looking at the POJO i posted, how would i write a Criteria query to get all RankProfiles with a specified id? Note that RankProfile has a many to one Rank relationship, so a Rank can be associated with many RankProfiles ... I think given such examples, i may be set to begin coding my Criterion queries