-->
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.  [ 5 posts ] 
Author Message
 Post subject: How to define prefix for tables and classes
PostPosted: Thu Mar 29, 2007 3:44 am 
Beginner
Beginner

Joined: Tue Feb 13, 2007 9:29 pm
Posts: 21
Hello,

Another newbie question.

How do I simplify my mapping by defining a prefix? How does that work? I looked over the documentation, can't find it anywhere.

for example, I have a table called "JumptreeForum_Discussions" and a class with the same name.

It's kind of tiring that I have to keep typing the prefix. I just want to simply type "Discussions" and mabye by defining the prefix "JumptreeForum_" somewhere and NHibernate can auto attach to it and find the table as well as the class. Is that possible?

Thanks and I'm using 1.2 beta


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 29, 2007 6:15 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Maybe NHibernate uses a similar concept of Hibernate?
http://www.hibernate.org/hib_docs/v3/re ... ngstrategy

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 29, 2007 8:54 am 
Beginner
Beginner

Joined: Tue Feb 13, 2007 9:29 pm
Posts: 21
hi batmat,

Thanks for your reply. I'm looking at the NamingStrategy, but still don't get it.

Do I Use " .setNamingStrategy(ImprovedNamingStrategy.INSTANCE)"? but where do i tell it to use "JumptreeForum_" prefix?

The document is pretty vague on that.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 29, 2007 9:20 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Implement a class that inherits NamingStrategy and do what you want. Here's the signature of it, quite straightforward(Note this code is Hibernate's one, but I guess it's quite close to this in NHibernate):
Code:
public interface NamingStrategy {
   /**
    * Return a table name for an entity class
    * @param className the fully-qualified class name
    * @return a table name
    */
   public String classToTableName(String className);
   /**
    * Return a column name for a property path expression
    * @param propertyName a property path
    * @return a column name
    */
   public String propertyToColumnName(String propertyName);
   /**
    * Alter the table name given in the mapping document
    * @param tableName a table name
    * @return a table name
    */
   public String tableName(String tableName);
   /**
    * Alter the column name given in the mapping document
    * @param columnName a column name
    * @return a column name
    */
   public String columnName(String columnName);
   /**
    * Return a collection table name ie an association having a join table
    *
    * @param ownerEntityTable owner side table name
    * @param associatedEntityTable reverse side table name if any
    * @param propertyName collection role
    */
   public String collectionTableName(String ownerEntityTable, String associatedEntityTable, String propertyName);
   /**
    * Return the join key column name ie a FK column used in a JOINED strategy or for a secondary table
    *
    * @param joinedColumn joined column name (logical one) used to join with
    * @param joinedTable joined table name (ie the referenced table) used to join with
    */
   public String joinKeyColumnName(String joinedColumn, String joinedTable);
   /**
    * Return the foreign key column name for the given parameters
    * @param propertyName the property name involved
    * @param propertyTableName the property table name involved (logical one)
    * @param referencedColumnName the referenced column name involved (logical one)
    */
   public String foreignKeyColumnName(String propertyName, String propertyTableName, String referencedColumnName);
   /**
    * Return the logical column name used to refer to a column in the metadata
    * (like index, unique constraints etc)
    * A full bijection is required between logicalNames and physical ones
    * logicalName have to be case insersitively unique for a given table
    *
    * @param columnName given column name if any
    * @param propertyName property name of this column
    */
   public String logicalColumnName(String columnName, String propertyName);
   /**
    * Returns the logical collection table name used to refer to a table in the mapping metadata
    *
    * @param tableName the metadata explicit name
    * @param ownerEntityTable owner table entity table name (logical one)
    * @param associatedEntityTable reverse side table name if any (logical one)
    * @param propertyName collection role
    */
   public String logicalCollectionTableName(String tableName, String ownerEntityTable, String associatedEntityTable, String propertyName);

   /**
    * Returns the logical foreign key column name used to refer to this column in the mapping metadata
    *
    * @param columnName given column name in the metadata if any
    * @param propertyName property name
    * @param referencedColumn referenced column name (logical one) in the join
    */
   public String logicalCollectionColumnName(String columnName, String propertyName, String referencedColumn);
}

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 29, 2007 8:25 pm 
Beginner
Beginner

Joined: Tue Feb 13, 2007 9:29 pm
Posts: 21
batmat!! it works!

that's awesome. really appreicate it.


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