Brian Storenson

Ranch Hand
+ Follow
since Aug 24, 2013
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Brian Storenson

I have three tables Lesson, Course, Program. Lesson has an attribute for Course's uuid, Course has an attribute for Program's uuid. How can I translate this to a Criteria API expression? Right now my statement returns a Path, and it's not returning any tuples.

I wrote out some sql to help me figure out what I needed to do. I think it should look something like this:

FROM Lesson AS l
ON l.Course=c.uuid
ON c.program=p.uuid
WHERE p.uuid = 'LessonSearchCriteria.PROGRAM_ID'

I am creating a dynamic query method that can search by Program_ID and by other characteristics if needed. My code looks like this as of right now:

I have also tried using the String versions of the join and get methods. Thanks!
Thanks Chris! I didn't think of looking for an open source ETL tool. These hints will be helpful
Oh yeah, I am now working on making a connection to an old version of the DB. I am going to use JDBC and sql statements. That is where I'm at right now. Thanks.
Hi, I need to write a DAO to extract data from an old sql server 2008 database. The data will eventually will be passed to other parts of the program that will then pass it to the new websites application layer. The new website will then take the data and use it to create new members for its database. We don't want to loose any data. The old DB has a lot of stored procedures. I've read a wiki on data migration, and looked at some postgres docs on data migration.

What do I need to research next to do this data migration? I have a big script that I created on sql server. I'm stuck right now. Thanks.
I'm trying to write an integration test that queries an hsql database. I'm using hibernate/spring. My program seems to throw up on line 68. When I highlight query.getResultList() while I am debugging the test, it says:

query.getResultList() = >Exception occurred in target VM: org.hibernate.SessionException: Session is closed!<

It seems like I am losing the context. How do I reopen the transaction, or keep the transaction open so I can query the database?

Here is my stack trace

Here is my integration test

I am having problems building my EntityManagerFactory. I think it is related to my persistence.xml. I have been working at this problem for the last 5-6 hours I think I have run out of resources. I would appreciate any tips. Thanks.

Here is my error message

Here is my integration test

Here is my persistence.xml

I've looked through my pom.xml and made sure everything was there. I tried looking through my dependencies. I have my hibernate entity manager jar, and my hibernate jpa model gen jar. I've tried <provider>org.hibernate.ejb.HibernatePersistenceProvider</provider> and <provider>org.hibernate.ejb.PersistenceProvider</provider> I've also tried <jta-data-source>java:/jdbc/TestDB</jta-data-source> Lastly, I've tried different schema locations. One of them is commented out. Does anyone have any suggestions? Are there topics I can try googling?

I read 1.2.1. The persistence.xml file at

Btw, I'm using this hibernate version:
I want to annotate my classes using Hibernate. Suppose you have a UML diagram were you have a Person as a superclass, and a Member who is a child class of Person. Then you have Member who can be composed of many EmergencyContacts:

EmergencyContact *----1<> Member ----> Person

The Member will have an attribute of type List<EmergencyContact>. The EmergencyContact will have a foreign key called Member_Id that points to an Id in Member. I'm going to annotate the inheritance relationship between Person with @MappedSuperclass and Person with @Entity. How would you annotate EmergencyContact? Is there a best way to design a database with a composite relationship like this, or is the choice debatable? Should I create another table by labeling EmergencyContact with @Entity?
6 years ago

James Boswell wrote:I agree with Campbell. Instead of calling:


I would remove the getPersonAddress method altogether and implement similar logic in the toString method of Address.

Also, consider the following:
- Rename streetAddress to street within the Address class
- Addresses usually have a house number or name so perhaps houseNumber should be renamed. It should also be a String instead of an int in this case
- As you are using JPA annotations, you should probably consider adding @OneToOne to the address within the Person class

Thank you for the helpful comments!
6 years ago

Campbell Ritchie wrote:There is something wrong about having the address field as an Address object, and returning a String from the getAddress method. That breaches the principle that each class takes responsibility for itself. You should have a toString method overridden in the Address class, and the getAddress method should return an Address object.

Thank you! I was thinking that was poor OO design, but I didn't know the proper way to implement.
6 years ago

Bear Bibeault wrote:Where are you getting the NPE? Don't make people guess.

I think it is when I call the getPersonAddress(). I changed the method so that it would check to see if the Object was null. Now it looks like this, and it works.

6 years ago
On line 18 of the Person.class I tried to create an instance to deal with the null pointer exception. It was originally like this:

6 years ago
I'm trying to create a demo website as an exercise. I want to be able to create a Person.class, and an Address.class. I want to associate an address to a person. I want to be able to create a Person without having to create an Address at the same time. I am getting a null pointer exception when I try to create a Person, because my Address is null. How should I design this?

6 years ago
I am new to unit testing, and I am trying to test the handleCriteria(). I wanted to verify that root.get(Person_.firstName) on line 26 occurred. But, I am getting a null pointer exception. I am having a hard time figuring out how to mock things, and use when(). I have read some of the mockito docs, and other tutorials. According to stack,

"A unit test should test a single codepath through a single method. When the execution of a method passes outside of that method, into another object, and back again, you have a dependency.

When you test that code path with the actual dependency, you are not unit testing; you are integration testing. While that's good and necessary, it isn't unit testing."

How can I test handleCriteria, and get rid of this null pointer exception?

6 years ago
This is supposed to be a good tutorial on JPA Criteria API:

I will start reading that now.
6 years ago