Hibernate Support in Selena

I just played a little with hibernate facet and here is my thoughts
1. If cfg.xml file present in the classpath but not in the source folder it is invisible for Idea
2. Spring org.springframework.orm.hibernate3.LocalSessionFactoryBean is not supported at all, personally I don't use the default hibernate session cfg file so I spent some time until Idea discovered the mapping
3. Would be nice to be able manually setup Hibernate facet profile e.i. been able to add datasource, and set of the mapping files vs relying on the cfg.xml file
4. After been able to setup all of the above the code assist works in the mapping file, but when I reopen the file everything is highlighted in red.

16 comments

Hello Vladimir,

2. Spring org.springframework.orm.hibernate3.LocalSessionFactoryBean
is not supported at all, personally I don't use the default hibernate
session cfg file so I spent some time until Idea discovered the
mapping


LSFB support is present, and works for me.
Can you give more details on your configuration?

-tt


0

I use spring conf file which is my classpath (not in the source folder but the directory is added to the module dependencies) please see my file below.

Thanks

trade.hbm.xml com/dao/mapping/user.hbn.xml com/dao/mapping/group.hbn.xml com/dao/mapping/resource.hbn.xml com/dao/mapping/menu.hbn.xml com/ecommerce/dao/mapping/product.hbn.xml com/ecommerce/dao/mapping/checkout.hbn.xml com/ecommerce/dao/mapping/address.hbn.xml ]]>
<!<prop key="hibernate.dialect">org.hibernate.dialect.SybaseDialect</prop>>
org.hibernate.dialect.MySQLDialect true false 20 true]]>
<!2.1>
org.hibernate.hql.classic.ClassicQueryTranslatorFactory]]>
<!3.0>
<!<prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop>>
]]>
<ref bean="$"/>
]]>
<property name="jndiName" value="$"/>
</bean>
</beans>

0

Hello Vladimir,

Do you have a spring facet configured, and does it include the config file
that contains the LSFB declaration?

-tt


0

Thanks i didn't realize that spring facet is required for hibernate (which actually makes sense) after configuring spring facet the code assist started to work but entire file is steel highlighted in red even if the value is selected from the code assist dropdown.

Thanks again for your response.

0

Hello Vladimir,

Thanks i didn't realize that spring facet is required for hibernate
(which actually makes sense) after configuring spring facet the code
assist started to work but entire file is steel highlighted in red
even if the value is selected from the code assist dropdown.


It's not really required: the Hibernate facet can read hibernate.cfg.xml,
and get all information from that.
What file is red, and what is the error displayed?

-tt


0

mapping file see below is red Idea cannot recognize class name and all the properties (I can CTRL_Click on any field and class name but it still shows in red) I have properties file in the separate folder which is added to the classpath (dependency tab)

<?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>
<class name="com.Trade" table="TC_Trade">

0

Hello Vladimir,

mapping file see below is red Idea cannot recognize class name and all
the properties (I can CTRL_Click on any field and class name but it
still shows in red) I have properties file in the separate folder
which is added to the classpath (dependency tab)


If I understand correctly, it seems that referenced Java classes cannot be
resolved.
Are there any other errors displayed in addition to that?

Does the module that contains the Hibernate facet contain the referenced
classes?
If the classes are in another module, does the modules containing the Hibernate
facet have a dependency on that other module?

-tt


0

all the classes in the same module

0

BTW I just found another problem with support LSFB.
if referenced mapping file is not present in the current module but is in the classpath through Module Dependencies setting then it is ignored by the facet. in my view it is serious problem since usually we have services spread out across multiple module and then reference them in the one master module such as Web etc.

Additionally Spring and Hibernate support should be project vs module based, by the end of the day they all in the same class path so it has no sense to have separate per module configuration.

Please take a look on it. Thanks

0

Vladimir,

Can you reproduce this in a isloated way? Meaning single module with just a few classes and the Hibernate facet.

If so, please create a JIRA issue, and add such a minimal testcase. This will greately improve the odds of getting it fixed quickly.

0

Can you quote actual code (for the LSFB declaration), and provide more details?
Are the references mapping files part of the source tree for the other module?

0

Oops, I see you already quoted LSFB declaration earlier in the thread.

It seems Hibernate/Spring integration is somewhat broken in #7041.

By the way, why are your .hbm.xml files not part of the source tree?

0

Hello!

On this page http://www.jetbrains.com/idea/nextversion/ it sais that the latest M2 build supports, among others, "Generating Hibernate mapping from data source structure". Could you tell me how do I actually generate the hibernate mappings from the data source?

Thank you!

Dorian

0

It is a little hidden, but very helpful once you figure it out. After you add your database connection and your hibernate facet, change the project view to J2EE view. Right click on your hibernate artifact and look near the bottom. It is the key to paradise. :) I have noticed that primary key classes that are generated do NOT have column annotations and will cause faulty queries to be generated for hibernate. I don't know if the same problem exists if you tell it to generate hbm files. I filed a bug yesterday.

0

Thank you very much!!

I never looked near the bottom of the list, looked over and over to the New submenu...

Any idea if Idea knows how to generate one Mapping file per table? Now it seems it generates one big file containing all the mappings.


Dorian

0

Sorry, I have moved onto annotations. You can probably accomplish that by selecting each table individually, then running the generation. That does not sound like a good solution. You may need to file a request for a new feature.

0

Please sign in to leave a comment.