13 comments

Hello Tom,

Hm, please excuse the dumb question, but how to use the hibernate
integration?


Add the Hibernate facet to a module.
I think it looks for hibernate.cfg.xml in root package of the source root(s)
of you module.
If you're configuring Hibernate through spring (LocalSessionFactoryBean etc),
the Hibernate facet can (try to) retrieve that information from the Spring
facet as an alternative.

In general the Hibernate support works well for me - in recent EAP buils.

Downsides (aka "hopes for the future"):
-resolving of HQL queries is limited to the module that has the facet.
I have a lot of DAO code in a dependent module, but all the (spring) configuration
is inside the main web module.
It would be nice if I could somehow "link" the facet behaviour from various
dependent modules to the web module.
-no support yet for parsing HQL defined in concatenated string blocks.

-tt


0

Taras Tielkes wrote:

I think it looks for hibernate.cfg.xml in root package of the source
root(s) of you module.


Does the file -have- to be called hibernate.cfg.xml - for some reason
ours is named differently (although easily changed if need be).

0

Hello Mark,

Does the file -have- to be called hibernate.cfg.xml - for some reason
ours is named differently (although easily changed if need be).


I'm not sure - Gregory will probably comment on this.
However, it looks like in #7051 the Hibernate facet contains a UI to explicitly
select a file.

Out of curiosity - why do you use a different name? How will Hibernate itself
know where to look?

Regards,
Taras


0

Thanks so far. What hibernate libraries do I need for basic work? Do I have
to run a database in parallel?

0

Hello Tom,

Thanks so far. What hibernate libraries do I need for basic work? Do I
have to run a database in parallel?


For the basic functionality in IDEA to work I'm not sure if hibernate libraries
are strictly needed.
However, some configuration properties in hibernate.cfg.xml (or in the equivalent
spring LSFB configuration) refer to Hibernate classes.
So I assume it would be a good idea to at least add "hibernate3.jar" as a
library dependency to your module.

(Or did you mean to ask which libraries Hibernate itself needs at runtime?)

As for the database...The Hibernate facet can complete/validate references
to database tables and columns.
This works in foo.hbm.xml mapping descriptors. I assume it works in the annotation-based
configuration as well.
To enable this IDEA needs to read in your DB schema. To enable this you need
to "pair" a Hibernate session factory with an IDEA Datasource.

The datasource can be defined (or imported) using "Tools...Datasource".
The "pairing" can be done in the config dialog of the Hibernate facet.

I assume that IDEA caches the DB schema, so as to enable the validation/completion
in "offline mode". Haven't checked though.

-tt


0

Hello Taras,

While testing I have checked that Configuration.configure("renamed-hibernate-file.cfg.xml")
works. Not sure about denoting path different from classes directory root...

How will Hibernate
itself know where to look?

Regards,
Taras

Alexander.


0

Taras Tielkes wrote:

I'm not sure - Gregory will probably comment on this.
However, it looks like in #7051 the Hibernate facet contains a UI to
explicitly select a file.


handy - thou i'll most likely rename the file :)

Out of curiosity - why do you use a different name? How will Hibernate
itself know where to look?


Allow me a moment to cry. Actually no, from what I understand - when
the project was originally written it was designed with two sub-modules
(user managment and billing), for various reasons of security the
developer decided to use two separate hibernate session factories, with
different caching/security settings.

At some point the code was refactored to only use one hibernate session
and the 2nd configuration file was removed, only the remaining one
wasn't renamed.

0

Hello Mark,

>> I'm not sure - Gregory will probably comment on this.
>> However, it looks like in #7051 the Hibernate facet contains a UI to
>> explicitly select a file.

handy - thou i'll most likely rename the file :)


After checking again it seems that #7051 is hardwired to only accept "hibernate-config.cfg.xml".
This seems a strange default: the hibernate manual mentions "hibernate.cfg.xml"
as the filename that the classpath is scanned for at startup.

A google search for "hibernate-config.cfg.xml" yields 0 results, so I assume
this is simply a bug in the Hibernate facet.
I think IDEA should allow the file to have any name (for maximum flexibility).

New JIRA issue filed: http://www.jetbrains.net/jira/browse/IDEA-13633

-tt


0

OK, I've played a little bit with Hibernate 3.2.4 and tutorials in its pdf
documentation. One this is strange: the book (and Hibernate itself) require
a file hibernate.cfg.xml in the classpath, but IDEA does not recognize it
and creates hibernate-config.cfg.xml itself. Does IDEA support a different
hibernate version?

0

The datasource can be defined (or imported) using "Tools...Datasource".


Does that work for you in #7051?

0

Hello Tom,

This is a bug: http://www.jetbrains.net/jira/browse/IDEADEV-18660.
Actually Hibernate can work with any file name. Default is "hibernate.cfg.xml".

OK, I've played a little bit with Hibernate 3.2.4 and tutorials in its
pdf documentation. One this is strange: the book (and Hibernate
itself) require a file hibernate.cfg.xml in the classpath, but IDEA
does not recognize it and creates hibernate-config.cfg.xml itself.
Does IDEA support a different hibernate version?

Alexander.


0

Fixed, thanks.

Any name allowed, as well as any number of descriptors.
Default hibernate descriptors file names are fixed as well.

Taras Tielkes wrote:

Hello Mark,

>>> I'm not sure - Gregory will probably comment on this.
>>> However, it looks like in #7051 the Hibernate facet contains a UI to
>>> explicitly select a file.
>> handy - thou i'll most likely rename the file :)


After checking again it seems that #7051 is hardwired to only accept
"hibernate-config.cfg.xml".
This seems a strange default: the hibernate manual mentions
"hibernate.cfg.xml" as the filename that the classpath is scanned for at
startup.

A google search for "hibernate-config.cfg.xml" yields 0 results, so I
assume this is simply a bug in the Hibernate facet.
I think IDEA should allow the file to have any name (for maximum
flexibility).

New JIRA issue filed: http://www.jetbrains.net/jira/browse/IDEA-13633

-tt

0

After checking again it seems that #7051 is hardwired to only accept
"hibernate-config.cfg.xml".


Well, I've found out, that when creating a hibernate-config.cfg.xml and then
renaming it to hibernate.cfg.xml (using Shift+F6), IDEA will accept it.

0

Please sign in to leave a comment.