Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!

Marcin Mogiela

Greenhorn
+ Follow
since Aug 30, 2007
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 Marcin Mogiela

"Effective Java second edition" by Joshua Bloch writes that one of the advantages of static factory methods is that they reduce the verbosity of creating parametrized type instances.

Such as:

and a wordy declaration:

could be replaced by more succinct alternative. Example:

I think the question is not the usefulness of such practices, but why it is impossible to use HashMap.getInstance() method invocation as an argument to a method. Such method does not really exist but suppose it does. The example comes from the book.
[ November 03, 2008: Message edited by: Marcin Mogiela ]
12 years ago
Hi

Scope attribute names in Servlets/Jsp are strings. Due to typing errors it is bad to use them as such.

It would be good to have an enum or an interface with string constants. But having such an interface it

becomes a dependency magnet, every servlet and jsp in the system depends on it and requires

recompilation on every attribute name change or attribute addition.

It there any best practice or pattern to handle scope attribute names?

Thanks,
Marcin
12 years ago
Hi,

Let's see on many-to-one element. It describes a property user of a class and indicates an association.



In the below snippet we have many-to-many element as a sub-element of set.
The set element describes a class property adverts.
The many-to-many sub-element says that adverts property implements many-to-many association between this and a given class.



Wouldn't it be more consistent (see my first example) if many-to-many element was superior to the set element?. It could be like this:



Thanks,
Marcin
[ June 28, 2008: Message edited by: Marcin Mogiela ]
Hi Pradeepta,

I did something like below, though it may not be the optimal solution.

If anybody had better solution for this problem or found any flaw in the problem itself I would highly appreciate any suggestions.

First of all I introduced the join class Enrollment.



From Enrollment.hbm.xml


From Course.hbm.xml


From Student.hbm.xml


From Grade.hbm.xml
I have a question about this practice of using HibernateUtil class.

Why is such class not provided by the framewordk out of the box? On every tutorial there are descriptions of SessionFactory, Configuration, etc classes, and then HibernateUtil is introduced that hides the details. Wouldn't the api be simpler if there was only one HibernateUtil class for us to use?
Perhaps these classes gives us more flexibility but isn't it lost by having HibernateUtil class?

Thanks,
Marcin
The answer to my question:
"create-drop with c3p0 causes SQLException"

There is a bug in hibernate. Today I found the description on http://opensource.atlassian.com/projects/hibernate/browse/HHH-2694

I still have a question about this practice of using HibernateUtil class.

Why is such class not provided by the framewordk out of the box? On every tutorial there are descriptions of SessionFactory, Configuration, etc classes, and then HibernateUtil is introduced that hides the details. Wouldn't the api be simpler if there was only one HibernateUtil class for us to use?
Perhaps these classes gives us more flexibility but isn't it lost by having HibernateUtil class?

Thanks,
Marcin
[ June 17, 2008: Message edited by: Marcin Mogiela ]
It is strange. If it was about this multi threading thing I think the close method would not been implemented right. It could wait till it is possible to close.

I wanted to use ServletContextListener to build session factory on contextInitialized and close it on contextDestroyed which I thought was a good idea.

I am learning hibernate and tried to use this setting:
hibernate.hbm2ddl.auto=create-drop
to drop my schema after I stop Tomcat server.




But when I stop my Tomcat server it crashes.
Here are also the logs from log4j:
When I invoke close on SessionFactory I get an exception:

java.sql.SQLException: com.mchange.v2.c3p0.PoolBackedDataSource@95504d20 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@fa5ceb37 [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, debugUnreturnedConnectionStackTraces -> false, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 2wf6bc7u12tsfuthqwmyv|fa5ff3, idleConnectionTestPeriod -> 3000, initialPoolSize -> 2, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 5000, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 2, maxStatements -> 100, maxStatementsPerConnection -> 0, minPoolSize -> 2, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@48c6ef14 [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 2wf6bc7u12tsfuthqwmyv|8acfc3, jdbcUrl -> jdbc:mysql://localhost/examscam, properties -> {user=******, password=******} ], preferredTestQuery -> null, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false; userOverrides: {} ], dataSourceName -> null, factoryClassLocation -> null, identityToken -> 2wf6bc7u12tsfuthqwmyv|1238785, numHelperThreads -> 3 ] has been closed() -- you can no longer use it.
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.assertCpds(AbstractPoolBackedDataSource.java:447)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getPoolManager(AbstractPoolBackedDataSource.java:459)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDa


hibernate.properties


my code:


Everything is ok when hibernate.c3p0.* properties are not set.
Do you know what might be the reason why it is not working?
[ June 15, 2008: Message edited by: Marcin Mogiela ]
Hi,

Is the book Hibernate made easy a paper version of tutorials available on
http://www.hiberbook.com/HiberBookWeb/learn.jsp ?
So is its content available for free or does its paper version offer more?

Thanks,
Marcin
[ May 22, 2008: Message edited by: Marcin Mogiela ]
Hi Cameron, it's a pleasure talking to you

The example from http://java-aap.blogspot.com/2006/04/hibernate-annotations-composite.html is a little too advanced for me.
I have only two days experience with hibernate and have read half and a little tutorial from your site http://www.hiberbook.com/HiberBookWeb/learn.jsp

All I understood from the example was that if a join table has its own properties a new POJO should be created


Now for the magic:
I've added 2 extra getters and setters for Product and Item to make it easier to get or set a product or item on your primary key. I added to extra columns to make hibernate think there is a Product mapped to this table (and an Item) but hibernate never updates or inserts this property (becuase it doensn't exists in our db.) But when hibernate does the getProduct() method it will retrieve the Product from our composite foreign key and all will work fine!



I don't understand this magic. Right now it seems to me like a hack

Thanks
[ May 19, 2008: Message edited by: Marcin Mogiela ]
Hi,

There is a "student" table and a "course" table (many to many relationship)
There is also a "grade" that I wanted to join with the "student_course" join table. (many one)

How can I do it in Hibernate? I am confused because "student_course" join table will be generated by Hibernate through @ManyToMany annotation


Thanks,
Marcin
Lets assume we have the following:



Test cases:



What would be the best solution to test h() method?

* one solution that comes to my mind is:


* 2nd solution:


* 3rd:

[ March 20, 2008: Message edited by: Marcin Mogiela ]
12 years ago
Thanks for the quick response.

The application I work on uses a system property to get a path to a file with other configuration properties. It is very difficult to change existing behavior. The system property is set at the time of Tomcat startup.
I would like to have two instances of the application running under one server and the problem is that they share the same global system property.
13 years ago
Hi,

Is there a way to run two different applications on two different virtual machines running under the same tomcat server?

Thanks,
Marcin
[ November 14, 2007: Message edited by: Marcin Mogiela ]
13 years ago