Maciej Opala

Ranch Hand
+ Follow
since Jul 18, 2011
Merit badge: grant badges
For More
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
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Maciej Opala

Bear Bibeault wrote:There are no "best" patterns. There are just applicable ones.



That's the point!
Finally (after 4 days of googling) I've (probalby) found a solution to my problem. No idea how to resolve this. I need to store CID.
Ok, will take it into consideration and thanks for useful advice.
But apart from the design of DB schema my main question was why hibernate executes so many selects? As I mentioned CP part might be nullable. It looks like the selects are executed to ensure that the result is really null :/ Any help/idea on this topic?
The real names are descriptive enough ;] But thanks.

Thanks also for the advice, but I just can't switch the tables (constraints). CE is as master table where the data is imported, so entries appear first in CE table (CE to CP foreign key abuses this). As I mentioned at the beginning there may be many entries in CE with same CID and different import_date. When users edits entry from CE new recored is inserted to CP (one for all entries in CE with same CID and different import_date). CP is used to keep common state for all entries in CE with same CID. So as you see I need this constraint on CP side. Weird. I know. I see that this is not mapping problem but DB design problem.
Here's my DDL statement:

I still get the same error mentioned before. I need the unique constraint over cid in CP table (many to one relation).

Martin Vajsar wrote:Unique constraint on CE(imp_date, cid) doesn't prevent the foreign key to be created.



Well, as far as I see this constraint prevents me from creating foreing key from CP(cid) to CE(cid). I get ORA-02270 error. Am I doing something wrong?
Thanks for the response.
The relation is established only in entities. There's no relation on DB level (FK) because of unique(imp_date, cid) in CE, and there's no such field (imp_date) in CP - so I can't add a FK constraint. How to resolve this? I need this unique constraint in CE, but I also want to establish many-to-one relation in DB for CE (many) to CP (one).
Hi,
I've very strange problem with hibernate and just can't work it out. The details below.

There are two tables CE and CP.

CE {
id pk
imp_date not null
cid not null
//other fields
unique(imp_date, cid)
}

CP {
id pk
cid not null unique
//other fields
}

The CE has ManyToOne relationship with CP (the purpose is to maintain common state of CE among various data imports - CP holds editable state of CE) but entry in CP for a CE might be null, so CP is nullable. There are no links on DB level (FK) between two tables. When I fetch CE from DB I'd also like to fetch the editable part (CP) so I need data from both tables. I have the following entry in CE entity:


The query looks like:

And is mapped to:

As far as I know the result of the query is enough to get all the data I need, but after this query there are multiple following queries:

The second query is repeated exactly as many times as there empty records of CP (all nullable). E.g. there are 1000 CE and only 10 has state in CP, the second query will be executed 990 times, which slows down the application.
How to prevent the second query to be executed? I've no idea what to do. Tried unidirectional as well as bidirectional relations, FK on DB level and many, many else.
Hi,
I've the following problem and need a piece of advice in design.

There are two classes of business objects from financial domain: A and C, and A contains a collection of C. An user may request to calculate (refresh the indexes, recalculate the debt and so on) the objects of this classes. The problem is that A requires some data from the collection of C to be fully calculated and C, also requires some data from A to be fully calculated. Currently, all the calculations are done in on class , fortunately not in one method. This design is in conflict with clean code principle (the code is very messy and unclear) and I'd like to refactor the code. The problem lies in the two-way dependencies.

My idea is to create AbstractCalculator class which will hold the currentlyCalculatedA and other common fields that are required for calculation (configuration, info-services). Then I will create ACalculator and CCalculator that both extend AbstractCalculator, also ACalculator has an instance of CCalculator.
Then in ACalculator:
- A is calculated till possible
- Collection<C> is calculated with usage of CCalculator
- A is calculated till the end
- the state of AbstractCalculator is reseted and waits for the next calculation.

Here is the diagram:




Will it be good designed or maybe someone has a better idea?


Hi,
I've the following configuration for jetty runner:


Is it possible to secure the jndi context with a password? And how to do it?
11 years ago
Thanks for all the valuable advice. Will check in the nearest future (now I'm fighting with another part of my hibernate application).

I use "EAGER" because I build a result object (consisting of A1 and A2) at once in the place I fetch the data.
Have set the following properties:

Hasn't helped even a bit but I guess it should be left as is right now. Will try indexing later.

Bill Gorder wrote:Why is your pool size set to 1? I hope you are not using hibernates pooling algorithm. This is not meant for production systems. See the documentation here:
http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/session-configuration.html#configuration-hibernatejdbc



To be honest I don't know what pooling algorithm is in use. Default for Hibernate 4.1. What should be the pool size? Thanks for the link, will check.

I would also make sure that the columns you are querying are on are properly indexed. I would run the execution plan and make sure you don't have full table scans happening. Probably speak to a DBA if you have one available.



Actually, the columns are not indexed at all right now. Will also check.
Thanks for being helpful.
Also overriding hashCode() and equals() might be useful if You store objects with a collection.
Hi,
I have 4 tables in DB:
- A1 one-to-one with A2 with mapping fetched with the following query
and
- C1 one-to-one with C2 with mapping fetched with the following query
From both results I construct a result object. There's also no relation (in hibernate) between A1 and C1.

The problem is that it takes about 12 seconds to fetch 500 (A1 with A2) and 2500 (C1+C2) records from the db. Hibernate constructs single query for each 'get' operation instead of (?) fetch all rows and process them on java side. How to tune this?
I also have the following properties set in my configuration:


Any help would be greatly appreciated..