Shannon McGee

+ Follow
since Oct 01, 2009
Merit badge: grant badges
For More
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 Shannon McGee

No problem!

Glad you got things squared away.
Is it possible to push the PK down into an aggregated entity that contains other non-key attributes?

@IdClass and @EmbeddedId allow you to define a PK (or composite key) in an aggregated entity.

But is it possible to map something like:

And yes, I know this is just a bad idea

Do you have cascading set up? If you are inserting them yourself, you only need to do one or the other.
I don't completely understand what you are trying to do.

Do you want the result sets from two unique tables to be merged into a single result set?

I've found the wrapper classes most useful for attributes that could be zero, but need to be set.
An int attribute set to "0" can be deceiving...
13 years ago
Hi Billy,

Since they are all seperate entities, I dont think there is a way around that. However, hibernate should help reduce the impact of all the calls w/ the shared cache and connection pooling.

Hi Anil,

The first thing that caught my eye is that your password is never set. Did you remove it to post the example, or forgot to set it in your code?

It looks like your persistence.xml file is never read. Is it on the classpath?

Hi Jan,

A mapping really repends on your DB. What are you mapping it to?


How are you running a query on a class that doesn't map to a table?
If you want to insert/ retrieve the class from the DB, you will need to annotate the class.
Hi Ashish,

The last time I used Hibernate I discovered that it cannot handle 2 data sources. I don't believe Hibernate has been updated since.

Are you sure you can use 2 data sources?

Hi Durga,

Is the primary key the same? If so, you will over-write the existing records (if you are re-setting a counter, or something).
You may want to look into the annotation @GeneratedValue, an easy way to set up auto-incrementing in JPA.

Hi Koti and Vivian,

I noticed that in your base class haven't annotated your 'id' with @Id. That would be my first recommendation.

The simplest way to annotate an attribute as a sequence is:

I believe the default sequencing will be with a table named 'SEQUENCE', and the following attributes:
Hi Peter,

I would start by removing the "mappedBy" annotation from the getBookInfo method. You shouldn't need any additional annotations for this relationship

This annotation is typically used to map the reverse side of a relationship that has already been captured in another class.

A side note: you may find that it's easier to put the attribute annotations above each attribute declaration. I didn't see anything in your code that would necessitate using the annotations at the method level.

Hi Brendan,

Are the "Team", "Department", etc.. entities very similar? I am assuming there is a degree of over-lap if you are using a mapped superclass.

If so, my suggestion would be to put all types in a single (well managed!) table.

Doing this (and yes, using inheritance... but without the performance hit) you will have the table mapped in a base entity class (say, "Stuff"). Your table will contain an attribute that is a discriminator, probably an integer, to describe the type of that entry (eg, Team).

This base JPA mapping class will contain all of the table attributes that are common to all of your types.

After the @Entity and @Table annotations, include the following:

@Inheritance(strategy= InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="type", discriminatorType=DiscriminatorType.INTEGER, length=1)

Then, each of your types (Team, Department, etc..) will be mapped w/ a class extending the base table. The class will be annotated with:
@DiscriminatorValue(<type int value>)

.. and the class will define all of the attributes which are not common to all types.

And finally, in the end, you will be able to have a List<Stuff> in, for example, your Team class. The discriminators are used to instantiate every "Stuff" item appropriately, so you will get back a list of Team, Department, etc... items.

The bi-directional mapping can be captured in a simple lookup table w/ <stuff item id>, <stuff item id> attributes.

Hope this helps,

Hi Swetha,

You should add the "cascade" attribute to the OneToOne annotation.

Your annotation will then look like:
@OneToOne(fetch = FetchType.EAGER, cascade=CascadeType.ALL)

Adding the cascade annotation will persist, update, or delete the aggregated event when you take that action on the EventActivity.