-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Extending abstract pojo
PostPosted: Sun Oct 10, 2004 7:15 pm 
Regular
Regular

Joined: Thu Sep 23, 2004 11:53 am
Posts: 83
Hibernate version:

2.1.6

Mapping documents:

NA

Code between sessionFactory.openSession() and session.close():

NA

Full stack trace of any exception that occurs:

No Exception this is a design question

Name and version of the database you are using:

MySQL

The generated SQL (show_sql=true):

NA

Debug level Hibernate log excerpt:

16:27:36,134 INFO Environment:469 - Hibernate 2.1.6
16:27:36,154 INFO Environment:503 - loaded properties from resource hibernate.properties: {hibernate.connection.username=root, hibernate.connection.password=, hibernate.cglib.use_reflection_optimizer=true, hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect, hibernate.connection.url=jdbc:mysql://localhost:3306/services, hibernate.connection.driver_class=com.mysql.jdbc.Driver}
16:27:36,154 INFO Environment:529 - using CGLIB reflection optimizer
16:27:36,164 INFO Configuration:350 - Mapping resource: com/pojo/Quote.hbm.xml
16:27:36,725 INFO Binder:229 - Mapping class: com.pojo.Quote -> quotes
16:27:36,835 INFO Configuration:350 - Mapping resource: com/pojo/Symbol.hbm.xml
16:27:36,875 INFO Binder:229 - Mapping class: com.pojo.Symbol -> symbols
16:27:36,885 INFO Configuration:627 - processing one-to-many association mappings
16:27:36,885 INFO Binder:1181 - Mapping collection: com.pojo.Symbol.quotes -> quotes
16:27:36,895 INFO Configuration:636 - processing one-to-one association property references
16:27:36,895 INFO Configuration:661 - processing foreign key constraints
16:27:36,915 INFO Dialect:82 - Using dialect: net.sf.hibernate.dialect.MySQLDialect
16:27:36,925 INFO SettingsFactory:59 - Maximim outer join fetch depth: 2
16:27:36,925 INFO SettingsFactory:63 - Use outer join fetching: true
16:27:36,925 INFO DriverManagerConnectionProvider:42 - Using Hibernate built-in connection pool (not for production use!)
16:27:36,925 INFO DriverManagerConnectionProvider:43 - Hibernate connection pool size: 20
16:27:36,975 INFO DriverManagerConnectionProvider:77 - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/services
16:27:36,975 INFO DriverManagerConnectionProvider:78 - connection properties: {user=root, password=}
16:27:36,985 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
16:27:37,196 INFO SettingsFactory:103 - Use scrollable result sets: true
16:27:37,196 INFO SettingsFactory:106 - Use JDBC3 getGeneratedKeys(): true
16:27:37,196 INFO SettingsFactory:109 - Optimize cache for minimal puts: false
16:27:37,206 INFO SettingsFactory:118 - Query language substitutions: {}
16:27:37,206 INFO SettingsFactory:129 - cache provider: net.sf.hibernate.cache.EhCacheProvider
16:27:37,206 INFO Configuration:1116 - instantiating and configuring caches
16:27:37,346 INFO SessionFactoryImpl:118 - building session factory
16:27:37,536 INFO ReflectHelper:186 - reflection optimizer disabled for: com.pojo.Symbol, IllegalArgumentException: Cannot find matching method/constructor
16:27:37,576 INFO ReflectHelper:186 - reflection optimizer disabled for: com.pojo.Quote, IllegalArgumentException: Cannot find matching method/constructor
16:27:37,736 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
16:27:37,796 INFO SessionFactoryImpl:534 - closing
16:27:37,796 INFO DriverManagerConnectionProvider:143 - cleaning up connection pool: jdbc:mysql://localhost:3306/services


Look at the bold part the excerpt. I know why this happens but just want to make sure what I know is correct :). The pojo Hiberante makes is an abstract class (cool feature). so we have ...

public abstract class AbstractPojo
{
public constructor1() {}
public constructor2(param1) {}
public constructor3(param1, param2) {}
}

I created a concrete class that extends AbstractPojo so we now have ...

public class ConcretePojo extends AbstractPojo
{
public constructor1() {}
public constructor2(param1) {}
public constructor3(param1, param2) {}
}

Now, this will not produce the the two bold lines in the excerpt. In fact this runs straight through with no additional debug information other then the norm. To get the bold lines to appear as in the above excerpt ... do the following ...

public abstract class ConcretePojo extends AbstractPojo
{
protected constructor1() {}
protected constructor2(param1) {}
public constructor3(param1, param2) {}
}

The 2 protected constructors cause the "optimizer ... disable" messages to appear. I made them protected so that constructor3 would be the only option to the developer. This forces the pojo to be instantiated in a valid state as constructor3 contains validation code for the parameters. My question is ... what do loose by Hibernate not being able to "optimize the class"?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 11, 2004 1:28 pm 
Regular
Regular

Joined: Tue Sep 28, 2004 6:34 pm
Posts: 50
I do not see your mapping here.
Just an idea - did you try to use interface instead of abstract class?

I had a problem with abstract class - hibernate tried to create the instace of it - interface helped a little:)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 11, 2004 9:43 pm 
Regular
Regular

Joined: Thu Sep 23, 2004 11:53 am
Posts: 83
How to declare and interface within the descriptor file? I know by putting AbstractXXX infront of the lcass name but, InterfacdXXX has no effect.

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.pojo.Symbol" table="symbols" check="field">
<meta attribute="generated-class">com.pojo.AbstractSymbol</meta>
<id name="id" type="int">
<meta attribute="scope-set">private</meta>
<generator class="native"/>
</id>
<property name="country" type="string">
<meta attribute="scope-set">protected</meta>
<column name="country" length="32" not-null="true" index="IDX_CTY_EXH_SYM" unique-key=""/>
</property>
<property name="exchange" type="string">
<meta attribute="scope-set">protected</meta>
<column name="exchange" length="32" not-null="true" index="IDX_CTY_EXH_SYM" unique-key=""/>
</property>
<property name="symbol" type="string">
<meta attribute="scope-set">protected</meta>
<column name="symbol" length="8" not-null="true" index="IDX_CTY_EXH_SYM" unique-key=""/>
</property>
<set name="quotes" inverse="true" cascade="all-delete-orphan">
<key column="symbol_id"/>
<one-to-many class="com.pojo.Quote"/>
</set>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 12, 2004 11:09 am 
Regular
Regular

Joined: Tue Sep 28, 2004 6:34 pm
Posts: 50
Sorry I did not get your first post - I thought that it might have been some inheritance issue.

Quote:
I made them protected so that constructor3 would be the only option to the developer


For developer yes, but hibernate always uses default constructor to create object. (So far I have not seen a way to pass the parameters for the constructor in hibernate definitions.)

Just a few things to consider:
Is it pojo, or business object and should it validate itself?
Shouldn't the validation be in different layer?

Btw. I guess this is just typo:
public abstract class ConcretePojo extends AbstractPojo
hibernate may have some issues with creating the instance of it:)

and about the info you get (the one in bold) - quote from:
http://www.hibernate.org/116.html

Quote:
I get: reflection optimizer disabled
Thats quite okay. For some classes we can't use CGLIB for property access, so we have to fall back to reflection. This will have a very minor effect upon performance. (CGLIB's MetaClass can't access final properties or nonpublic properties.)



Lukasz


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 14, 2004 4:15 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Lukasz (Qr) wrote:
For developer yes, but hibernate always uses default constructor to create object. (So far I have not seen a way to pass the parameters for the constructor in hibernate definitions.)


Interceptor.instantiate(...)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 14, 2004 2:26 pm 
Regular
Regular

Joined: Tue Sep 28, 2004 6:34 pm
Posts: 50
I meant "pass parameters" in hibernate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.