facebook

Load hibernate configuration files programatically

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #259620 Reply

    frankc01a
    Member

    I want to set my JSF components constraints (length, etc.) via the values in the hibernate configuration files (xxx.hbm.xml).

    Anyone familiar enough with Hibernate to explain?

    MyEclipse 5.01, Hibernate 3.1

    Thanks in advance

    Frank

    #259621

    Frank,

    You can use Hibernate’s metadata.
    For example:

    MyPojo pojo = …;
    ClassMetadata pojoMetadata = sessionFactory.getClassMetadata(MyPojo.class);

    Object[] propertyValues = pojoMetadata.getPropertyValues(pojo);
    String[] propertyNames = pojoMetadata.getPropertyNames();

    See ClassMetadata and CollectionMetadata API for more informations.

    Regards,
    Snjeza

    #259634

    frankc01a
    Member

    Thanks, worked like a charm

    #259643

    frankc01a
    Member

    Actually, a new rub:

    I was able to use the following for normal tables, but it doesn’t work if the configuration is for a view:

    
        private    void extractMeta(Configuration cfg, Class c, Hashtable ht)
        {
            PersistentClass pcls = cfg.getClassMapping(c.getName());
            
            for(Iterator it = pcls.getPropertyIterator(); it.hasNext();)
            {
                Property p = (Property) it.next();
                
                for (Iterator iter = p.getColumnIterator(); iter.hasNext();)
                {
                    Column column = (Column) iter.next();
                    
                    ht.put(column.getName(), new Integer(column.getLength()));
                }
            }
            return;
        }
     
    
    #259777

    Frank,

    I suppose that all the view’s columns are included in Hibernate identifier.
    The method getPropertyIterator returns only simple properties.
    Try to use the method PersistentClass.getPropertyIdentifier.

    Regards,
    Snjeza

    #259819

    frankc01a
    Member

    Thanks again!

Viewing 6 posts - 1 through 6 (of 6 total)
Reply To: Load hibernate configuration files programatically

You must be logged in to post in the forum log in