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.  [ 4 posts ] 
Author Message
 Post subject: dynamically loading fields from table
PostPosted: Fri Dec 16, 2005 3:09 pm 
Newbie

Joined: Fri Dec 16, 2005 2:05 pm
Posts: 3
Hi,

I am looking to dynamically load the data for the entire record shown below without actually specifying each property in the mapping XML file. This is a requirement of the program that I am writing, as the Hibernate code must work without configuration modification if columns are added to or take out of the database. Is this possible?

I noticed that there was at one point an XML element named "dynamic-class" that was taken out of the DTD. Did this have anything to do with what I am looking to do?

The hibername.default_entity_mode for the SessionFactory is set to "dynamic-map".

Also, I apologize if I did not get the terminology correct. I am fairly new to Hibernate.

Thank you.

Hibernate version: 3.0.5

Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="mypackage">

        <class table="position" entity-name="DEFAULT" lazy="false">
                <composite-id name="key" class="maypackage.MyKeyClass">
                        <key-property name="col1" />
                        <key-property name="col2" />
                </composite-id>
                <!-- It works with the following line uncommented: -->
                <!-- <property name="col3" type="string" /> -->
        </class>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
Map m = new HashMap();
m.put("col1", col1Value);
m.put("col2", col2Value);
Map p = (Map) session.load("DEFAULT", (Serializable) m);
System.out.println("This should not be null: " + p.get("col3"));


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 19, 2005 12:49 am 
Regular
Regular

Joined: Wed May 05, 2004 3:41 pm
Posts: 118
Location: New Jersey,USA
Look at the Java API Doc for "org.hibernate.cfg.Configuration". It provides some hooks to via the "createMappings" method that should probably help you programatically configure your mappings.


Top
 Profile  
 
 Post subject: Post subject: dynamically loading fields from table
PostPosted: Mon Dec 19, 2005 10:32 am 
Newbie

Joined: Fri Dec 16, 2005 2:05 pm
Posts: 3
Thank you for your reply.

I read through the API, but it seems that I am missing something. Ideally, I would like a one-line solution similar to the following:

Code:
<class name="mytable" useAllColumns="true">


I understand that there is probably a good reason if this is not part of Hibernate's functionaliy, but is there another way to do this? It could be in code, SessionFactory configuration settings, or mapping XML. It would seem to me to be logical for this type of setting to be outside of code.

Perhaps there is a way to set Hibernate to default to adding all columns in a table rather than just those specified?

Thank you again for helping me.


Top
 Profile  
 
 Post subject: dynamically loading fields from table
PostPosted: Tue Dec 20, 2005 1:46 pm 
Newbie

Joined: Fri Dec 16, 2005 2:05 pm
Posts: 3
I just attempted to use this as a possible solution:

Code:
<property name="*" />


This naturally did not work, as it tried to generate SQL similar to:

Code:
select default0_.col1 as col10_, default0_.col2 as col20_, default0_.* as default0_ ...


Am I at all on the right path?

Thank you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.