21

I'm using JBoss Embedded version beta3.SP10 and I'm facing a persistence bug that is should be fixed in some Hibernate version. Sadly, I don't know what version of Hibernate is used in my JBoss Embedded and couldn't find a way to find this information, the hibernate-all.jar bundled in it doesn't contain a org.hibernate.Version class, nor a MANIFEST.

How can I find the currently loaded Hibernate version without using org.hibernate.Version?

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
Kawu
  • 13,647
  • 34
  • 123
  • 195
  • What is your use case exactly? Why not using the `Version` class if you have this need? – Pascal Thivent Aug 13 '10 at 22:19
  • Erm my Hibernate distribution doesn't have this class... It seems to have been added in the nearer past. The use case I have is a bug that I can't figure out: see http://forum.hibernate.org/viewtopic.php?f=1&t=1006411 This is because I use embedded JBoss on Tomcat and this distribution comes with Hibernate whose version I don't know. Chances are a newer version could resolve the issue (I posted a link to a bug report). – Kawu Aug 14 '10 at 00:10

5 Answers5

49

Try this,

System.out.println(org.hibernate.Version.getVersionString());

found here

Shell
  • 6,818
  • 11
  • 39
  • 70
max3d
  • 1,437
  • 15
  • 16
10

Another way to obtain the version.

System.out.println(org.hibernate.cfg.Environment.VERSION)

This is for older version of Hibernate. e.g. 3.3.1.GA

Hkachhia
  • 4,463
  • 6
  • 41
  • 76
g5thomas
  • 315
  • 1
  • 4
  • 14
  • Yes, for earlier ver i.e 3.2.x, only this will work. In earlier ver, Version constant doesn't appear in annotations.common. – peterong Feb 01 '18 at 07:09
6

This simple Java code is get the Hibernate version.

package com.test;
public class TestBean {
public static void main(String[] args) {
    try {
        String hibernateVersion = org.hibernate.annotations.common.Version.VERSION;
        System.out.println("Hibernate Version: "+ hibernateVersion);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
}

Output: Hibernate Version: 3.1.0.GA

UdayKiran Pulipati
  • 6,579
  • 7
  • 67
  • 92
0

I prefer the way of @Shell, not that of @pudaykiran. Actually, I found these two way get different input in my case. As said @pudaykiran, I got:

3.2.0 Final

And as @Shell said:

3.5.4 Final

I guess the 3.5.4 final version used org.hibernate.annotations.common of previous version. Correct me if I am wrong.

WesternGun
  • 11,303
  • 6
  • 88
  • 157
  • FWIW, those different commands returned different results for me as well: `System.out.println(org.hibernate.annotations.common.Version.VERSION)` returned `13.2.0.Final`, while `System.out.println(org.hibernate.Version.getVersionString())` returned `3.6.10.Final`. A newer (5.x) version only worked with the second command; the first one resulted in this exception: `No such property: VERSION for class: org.hibernate.annotations.common.Version` – Tracy Logan Feb 11 '22 at 21:12
  • 1
    Then I guess the 1st one does not work nowadays. – WesternGun Feb 14 '22 at 07:16
0

Indeed, it seems hard to find what exact versions of Hibernate modules are used. Some suggestions:

  1. Check if your Hibernate JAR has a META-INF/MANIFEST.MF with the version in it. It looks like the JBoss folks were using Ant at this time and the Manifest doesn't provide the version.

  2. Dig the JBoss Embedded SVN to find out what they're doing exactly.

  3. Try with JBoss embedded beta3.SP12 (that you can get from the Maven repository).

  4. Try to replace the hibernate-all with a bundle containing Hibernate EM 3.4.0.GA.

I would give options 3 and 4 a try.

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • I tried this before. No version there. I just found https://forum.hibernate.org/viewtopic.php?f=1&t=1003161&start=0 but I don't know where to put that param. I tried as context param in web.xml, but it doesn't work. BTW JBoss embedded is beta3.SP10, the latest from 2009-09-09. – Kawu Aug 14 '10 at 02:02