Close

HAR files and how to package them (in JBoss AS)

HAR file is short for Hibernate Archive File (in JBoss world). These types of files are being used to configure JBoss AS to utilize hibernate and access hibernate and be able to provide access to hibernate via itself to the client code. Configuration files can be archived in a .har file and deployed on the JBoss server. Minimum HAR file consists of the entity class heirarchy and its hibernate mapping files (hbm.xml) and an XML file resides under META-INF folder. The xml file which is needed to be ended with -hibernate.xml is for registering SessionFactory and how it handles sessions.

Let’s say you are trying to automate your build process, and you are using Ant. How many HAR files you want to generate and in what structure ?

The best is always the easiest, you only need a single .har file which has all the necessary classes and hbm.xml files.

hibernate.har

|META-INF

-|hibernate-xml-hibernate.xml

|org

-|domain

–|package

—|Entity.class

—|Entity.hbm.xml

—|AnotherEntity.class

—|AnotherEntity.hbm.xml

You can not have more than one har file with the same SessionFactory name in them. That will result in an exception. Also it won’t be a wise choice to have more than one SessionFactory.

hibernateAnotherEntity.har

|META-INF

-|hibernate-xml-hibernate.xml

|org

-|domain

–|package

—|AnotherEntity.class

—|AnotherEntity.hbm.xml

hibernateEntity.har

|META-INF

-|hibernate-xml-hibernate.xml

|org

-|domain

–|package

—|Entity.class

—|Entity.hbm.xml

You might want to create one har file with only the xml file under META-INF and have every class and its hbm.xml in another har file, this won’t work either. Since the SessionFactory have not been bound to the classes. The bounding is done by being in the same file (or folder).

hibernate-xml.har

|META-INF

-|hibernate-xml-hibernate.xml

hibernate-hbm.har

|org

-|domain

–|package

—|Entity.class

—|Entity.hbm.xml

Leave a Reply

Your email address will not be published. Required fields are marked *