Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

All extremists should be taken out and shot.


devel / comp.lang.java.programmer / Is there a simpler way to map Hibernate?

SubjectAuthor
* Is there a simpler way to map Hibernate?e.d.pro...@gmail.com
`* Is there a simpler way to map Hibernate?Arne_Vajhøj
 `* Is there a simpler way to map Hibernate?e.d.pro...@gmail.com
  `* Is there a simpler way to map Hibernate?Arne_Vajhøj
   `* Is there a simpler way to map Hibernate?e.d.pro...@gmail.com
    `* Is there a simpler way to map Hibernate?Arne_Vajhøj
     `* Is there a simpler way to map Hibernate?e.d.pro...@gmail.com
      `* Is there a simpler way to map Hibernate?Arne_Vajhøj
       +- Is there a simpler way to map Hibernate?e.d.pro...@gmail.com
       `* Is there a simpler way to map Hibernate?e.d.pro...@gmail.com
        `* Is there a simpler way to map Hibernate?Arne_Vajhøj
         +- Is there a simpler way to map Hibernate?e.d.pro...@gmail.com
         `- Is there a simpler way to map Hibernate?e.d.pro...@gmail.com

1
Is there a simpler way to map Hibernate?

<015e1e01-2e15-49bf-ae5e-07470e4e3d2bn@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=288&group=comp.lang.java.programmer#288

  copy link   Newsgroups: comp.lang.java.programmer
X-Received: by 2002:a05:622a:4:b0:410:9af1:f9db with SMTP id x4-20020a05622a000400b004109af1f9dbmr69734qtw.8.1693482575590;
Thu, 31 Aug 2023 04:49:35 -0700 (PDT)
X-Received: by 2002:a17:903:1c4:b0:1bc:4c3d:eb08 with SMTP id
e4-20020a17090301c400b001bc4c3deb08mr957841plh.8.1693482575323; Thu, 31 Aug
2023 04:49:35 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.java.programmer
Date: Thu, 31 Aug 2023 04:49:34 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=98.237.40.232; posting-account=2czF5goAAAD4GBMPIGV4KcD2K4PhoB_H
NNTP-Posting-Host: 98.237.40.232
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <015e1e01-2e15-49bf-ae5e-07470e4e3d2bn@googlegroups.com>
Subject: Is there a simpler way to map Hibernate?
From: e.d.programmer@gmail.com (e.d.pro...@gmail.com)
Injection-Date: Thu, 31 Aug 2023 11:49:35 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 1483
 by: e.d.pro...@gmail.com - Thu, 31 Aug 2023 11:49 UTC

I'm reading tables by putting @Entity and @Table on classes. For each of those I have to add a mapping tag in the session-factory tag in a hibernate.cfg.xml file in the src/main/resources folder, then copy this tag into the same file in src/test/resources? Is there a way to share regular mappings with unit testing? Is there a way to automatically include all entities, or a reason I shouldn't want to include all?

Re: Is there a simpler way to map Hibernate?

<ucr57u$3fa1g$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=289&group=comp.lang.java.programmer#289

  copy link   Newsgroups: comp.lang.java.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: arne@vajhoej.dk (Arne Vajhøj)
Newsgroups: comp.lang.java.programmer
Subject: Re: Is there a simpler way to map Hibernate?
Date: Thu, 31 Aug 2023 18:46:23 -0400
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <ucr57u$3fa1g$1@dont-email.me>
References: <015e1e01-2e15-49bf-ae5e-07470e4e3d2bn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 31 Aug 2023 22:46:22 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="cb85e14bf167dff1355501843a4c18ca";
logging-data="3647536"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18IWj9rxfH6RrWJOpUUoWFyYUAwdwlTwos="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.14.0
Cancel-Lock: sha1:iKugkQcwk7n33yH9ANQK1Labck8=
Content-Language: en-US
In-Reply-To: <015e1e01-2e15-49bf-ae5e-07470e4e3d2bn@googlegroups.com>
 by: Arne Vajhøj - Thu, 31 Aug 2023 22:46 UTC

On 8/31/2023 7:49 AM, e.d.pro...@gmail.com wrote:
> I'm reading tables by putting @Entity and @Table on classes. For each
> of those I have to add a mapping tag in the session-factory tag in a
> hibernate.cfg.xml file in the src/main/resources folder, then copy
> this tag into the same file in src/test/resources? Is there a way to
> share regular mappings with unit testing? Is there a way to
> automatically include all entities, or a reason I shouldn't want to
> include all?

If you use JPA annotations why do you need a Hibernate mapping
file at all?

Just use annotations @Id, @Column, @OneToMany on properties
to specify all the details on how to access database.

Arne

Re: Is there a simpler way to map Hibernate?

<c7dbfc66-c143-45f0-8501-50d9aa90e3b2n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=290&group=comp.lang.java.programmer#290

  copy link   Newsgroups: comp.lang.java.programmer
X-Received: by 2002:a05:620a:151:b0:76d:c9c7:dd6b with SMTP id e17-20020a05620a015100b0076dc9c7dd6bmr55584qkn.3.1693566494999;
Fri, 01 Sep 2023 04:08:14 -0700 (PDT)
X-Received: by 2002:a17:902:f686:b0:1bb:91c9:d334 with SMTP id
l6-20020a170902f68600b001bb91c9d334mr765907plg.0.1693566494541; Fri, 01 Sep
2023 04:08:14 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.java.programmer
Date: Fri, 1 Sep 2023 04:08:13 -0700 (PDT)
In-Reply-To: <ucr57u$3fa1g$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=98.237.40.232; posting-account=2czF5goAAAD4GBMPIGV4KcD2K4PhoB_H
NNTP-Posting-Host: 98.237.40.232
References: <015e1e01-2e15-49bf-ae5e-07470e4e3d2bn@googlegroups.com> <ucr57u$3fa1g$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c7dbfc66-c143-45f0-8501-50d9aa90e3b2n@googlegroups.com>
Subject: Re: Is there a simpler way to map Hibernate?
From: e.d.programmer@gmail.com (e.d.pro...@gmail.com)
Injection-Date: Fri, 01 Sep 2023 11:08:14 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1522
 by: e.d.pro...@gmail.com - Fri, 1 Sep 2023 11:08 UTC

> If you use JPA annotations why do you need a Hibernate mapping
> file at all?
>
> Just use annotations @Id, @Column, @OneToMany on properties
> to specify all the details on how to access database.
>
> Arne
I am using those annotations, and if I don't have the mapping tags in the cfg file, as soon as I call createQuery I get "... is not mapped"

Re: Is there a simpler way to map Hibernate?

<ucslb3$3p6nj$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=291&group=comp.lang.java.programmer#291

  copy link   Newsgroups: comp.lang.java.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: arne@vajhoej.dk (Arne Vajhøj)
Newsgroups: comp.lang.java.programmer
Subject: Re: Is there a simpler way to map Hibernate?
Date: Fri, 1 Sep 2023 08:27:15 -0400
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <ucslb3$3p6nj$1@dont-email.me>
References: <015e1e01-2e15-49bf-ae5e-07470e4e3d2bn@googlegroups.com>
<ucr57u$3fa1g$1@dont-email.me>
<c7dbfc66-c143-45f0-8501-50d9aa90e3b2n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 1 Sep 2023 12:27:15 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="cb85e14bf167dff1355501843a4c18ca";
logging-data="3971827"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/dDM5bKVecIL4cw+IwGS8UVaDd6T42xq4="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:6xLfuVfAshRT5Gz2Kd30LextCbc=
In-Reply-To: <c7dbfc66-c143-45f0-8501-50d9aa90e3b2n@googlegroups.com>
Content-Language: en-US
 by: Arne Vajhøj - Fri, 1 Sep 2023 12:27 UTC

On 9/1/2023 7:08 AM, e.d.pro...@gmail.com wrote:
>> If you use JPA annotations why do you need a Hibernate mapping
>> file at all?
>>
>> Just use annotations @Id, @Column, @OneToMany on properties
>> to specify all the details on how to access database.

> I am using those annotations, and if I don't have the mapping tags in
> the cfg file, as soon as I call createQuery I get "... is not
> mapped"

What do you have in persistence.xml?

Arne

Re: Is there a simpler way to map Hibernate?

<f0746a5b-9125-4055-b2a4-de230c621f6cn@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=292&group=comp.lang.java.programmer#292

  copy link   Newsgroups: comp.lang.java.programmer
X-Received: by 2002:ad4:59c4:0:b0:63f:8aaf:164c with SMTP id el4-20020ad459c4000000b0063f8aaf164cmr54293qvb.8.1693572549195;
Fri, 01 Sep 2023 05:49:09 -0700 (PDT)
X-Received: by 2002:a17:902:e850:b0:1bd:dcdf:6179 with SMTP id
t16-20020a170902e85000b001bddcdf6179mr795537plg.2.1693572548965; Fri, 01 Sep
2023 05:49:08 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.java.programmer
Date: Fri, 1 Sep 2023 05:49:08 -0700 (PDT)
In-Reply-To: <ucslb3$3p6nj$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=98.237.40.232; posting-account=2czF5goAAAD4GBMPIGV4KcD2K4PhoB_H
NNTP-Posting-Host: 98.237.40.232
References: <015e1e01-2e15-49bf-ae5e-07470e4e3d2bn@googlegroups.com>
<ucr57u$3fa1g$1@dont-email.me> <c7dbfc66-c143-45f0-8501-50d9aa90e3b2n@googlegroups.com>
<ucslb3$3p6nj$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f0746a5b-9125-4055-b2a4-de230c621f6cn@googlegroups.com>
Subject: Re: Is there a simpler way to map Hibernate?
From: e.d.programmer@gmail.com (e.d.pro...@gmail.com)
Injection-Date: Fri, 01 Sep 2023 12:49:09 +0000
Content-Type: text/plain; charset="UTF-8"
 by: e.d.pro...@gmail.com - Fri, 1 Sep 2023 12:49 UTC

> What do you have in persistence.xml?
>
> Arne
I don't have a persistence.xml in this project, just the hibernatecfg.xml.

I have another project using Hibernate through the Flowable framework which has a persistence.xml with persistence-unit tags containing class tags for every entity.
This one is just directly referencing Hibernate with session-factory.
new MetadataSources(new StandardServiceRegistryBuilder().configure().build()).getMetadataBuilder().build().getSessionFactoryBuilder().build()
try (Session session = getMyFactory().openSession();){

Re: Is there a simpler way to map Hibernate?

<ucsnkr$3pftv$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=293&group=comp.lang.java.programmer#293

  copy link   Newsgroups: comp.lang.java.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: arne@vajhoej.dk (Arne Vajhøj)
Newsgroups: comp.lang.java.programmer
Subject: Re: Is there a simpler way to map Hibernate?
Date: Fri, 1 Sep 2023 09:06:35 -0400
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <ucsnkr$3pftv$1@dont-email.me>
References: <015e1e01-2e15-49bf-ae5e-07470e4e3d2bn@googlegroups.com>
<ucr57u$3fa1g$1@dont-email.me>
<c7dbfc66-c143-45f0-8501-50d9aa90e3b2n@googlegroups.com>
<ucslb3$3p6nj$1@dont-email.me>
<f0746a5b-9125-4055-b2a4-de230c621f6cn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 1 Sep 2023 13:06:35 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="cb85e14bf167dff1355501843a4c18ca";
logging-data="3981247"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/HK4AJ1qta3Luaw4nesyoRyAsePA70bAY="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:HTiHJTvtA4hea0ILcWQ4ZYmQ9R8=
In-Reply-To: <f0746a5b-9125-4055-b2a4-de230c621f6cn@googlegroups.com>
Content-Language: en-US
 by: Arne Vajhøj - Fri, 1 Sep 2023 13:06 UTC

On 9/1/2023 8:49 AM, e.d.pro...@gmail.com wrote:
>> What do you have in persistence.xml?
>>
> I don't have a persistence.xml in this project, just the hibernatecfg.xml.
>
> I have another project using Hibernate through the Flowable framework which has a persistence.xml with persistence-unit tags containing class tags for every entity.
> This one is just directly referencing Hibernate with session-factory.
> new MetadataSources(new StandardServiceRegistryBuilder().configure().build()).getMetadataBuilder().build().getSessionFactoryBuilder().build()
> try (Session session = getMyFactory().openSession();){

So you are not using JPA with Hibernate as implementation - you
are using Hibernate with JPA annotations.

I believe that is supposed to work, but most people changed
from Hibernate with XML to JPA with annotations like 15 years
ago.

I have no idea about how Hibernate with JPA annotations.
work.

Any chance that you could change to JPA?

Arne

Re: Is there a simpler way to map Hibernate?

<69105518-21d7-468c-9774-e9ffb497677fn@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=294&group=comp.lang.java.programmer#294

  copy link   Newsgroups: comp.lang.java.programmer
X-Received: by 2002:a05:620a:40f:b0:76e:1a6a:165 with SMTP id 15-20020a05620a040f00b0076e1a6a0165mr61239qkp.14.1693574737295;
Fri, 01 Sep 2023 06:25:37 -0700 (PDT)
X-Received: by 2002:a17:902:f686:b0:1c1:f00a:64d5 with SMTP id
l6-20020a170902f68600b001c1f00a64d5mr865267plg.4.1693574736981; Fri, 01 Sep
2023 06:25:36 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border-2.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.java.programmer
Date: Fri, 1 Sep 2023 06:25:36 -0700 (PDT)
In-Reply-To: <ucsnkr$3pftv$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=98.237.40.232; posting-account=2czF5goAAAD4GBMPIGV4KcD2K4PhoB_H
NNTP-Posting-Host: 98.237.40.232
References: <015e1e01-2e15-49bf-ae5e-07470e4e3d2bn@googlegroups.com>
<ucr57u$3fa1g$1@dont-email.me> <c7dbfc66-c143-45f0-8501-50d9aa90e3b2n@googlegroups.com>
<ucslb3$3p6nj$1@dont-email.me> <f0746a5b-9125-4055-b2a4-de230c621f6cn@googlegroups.com>
<ucsnkr$3pftv$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <69105518-21d7-468c-9774-e9ffb497677fn@googlegroups.com>
Subject: Re: Is there a simpler way to map Hibernate?
From: e.d.programmer@gmail.com (e.d.pro...@gmail.com)
Injection-Date: Fri, 01 Sep 2023 13:25:37 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 13
 by: e.d.pro...@gmail.com - Fri, 1 Sep 2023 13:25 UTC

> So you are not using JPA with Hibernate as implementation - you
> are using Hibernate with JPA annotations.
>
> I believe that is supposed to work, but most people changed
> from Hibernate with XML to JPA with annotations like 15 years
> ago.
>
> I have no idea about how Hibernate with JPA annotations.
> work.
>
> Any chance that you could change to JPA?
>
> Arne
What is "JPA with Hibernate" versus "Hibernate with JPA annotations"? Is this just about using persistence.xml files with EntityManager? That still requires declaring every entity class in the xml file and duplicating that for test? What is the advantage?

Re: Is there a simpler way to map Hibernate?

<ucspf7$3ppii$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=295&group=comp.lang.java.programmer#295

  copy link   Newsgroups: comp.lang.java.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: arne@vajhoej.dk (Arne Vajhøj)
Newsgroups: comp.lang.java.programmer
Subject: Re: Is there a simpler way to map Hibernate?
Date: Fri, 1 Sep 2023 09:37:42 -0400
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <ucspf7$3ppii$1@dont-email.me>
References: <015e1e01-2e15-49bf-ae5e-07470e4e3d2bn@googlegroups.com>
<ucr57u$3fa1g$1@dont-email.me>
<c7dbfc66-c143-45f0-8501-50d9aa90e3b2n@googlegroups.com>
<ucslb3$3p6nj$1@dont-email.me>
<f0746a5b-9125-4055-b2a4-de230c621f6cn@googlegroups.com>
<ucsnkr$3pftv$1@dont-email.me>
<69105518-21d7-468c-9774-e9ffb497677fn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 1 Sep 2023 13:37:43 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="cb85e14bf167dff1355501843a4c18ca";
logging-data="3991122"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19GFwKdLmcyrsG04ml3A8Goqjpi+lU8o3w="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:4aqQZ+OBfCms2jS+f7o2fxq/4lo=
Content-Language: en-US
In-Reply-To: <69105518-21d7-468c-9774-e9ffb497677fn@googlegroups.com>
 by: Arne Vajhøj - Fri, 1 Sep 2023 13:37 UTC

On 9/1/2023 9:25 AM, e.d.pro...@gmail.com wrote:
>> So you are not using JPA with Hibernate as implementation - you are
>> using Hibernate with JPA annotations.
>>
>> I believe that is supposed to work, but most people changed from
>> Hibernate with XML to JPA with annotations like 15 years ago.
>>
>> I have no idea about how Hibernate with JPA annotations. work.
>>
>> Any chance that you could change to JPA?
>>
> What is "JPA with Hibernate" versus "Hibernate with JPA annotations"?
> Is this just about using persistence.xml files with EntityManager?
> That still requires declaring every entity class in the xml file and
> duplicating that for test? What is the advantage?

Yes. Basically:

EntityManagerFactory emf = Persistence.createEntityManagerFactory(confnam);
EntityManager em = emf.createEntityManager();

instead of:

SessionFactory sf = new Configuration().configure(new
File(conffile)).buildSessionFactory();
Session s = sf.openSession();

(your setup code is a little bit more advanced but above
is the basic version)

I see two advantages.

1) You switch to a mode that almost everyone else is using
so a lot better support and a lot easier to get help.

2) It is correct that the most common approach is to
have a persistence.xml with:

<class>p.C1</class>
<class>p.C2</class>
<class>p.C3</class>
<exclude-unlisted-classes/>

but you could try with:

<exclude-unlisted-classes>false</exclude-unlisted-classes>

I am not an expert in the finer points of JPA, but I remember
it as that false should work in Java EE context and that it
is not guaranteed to work in SE context but usually does.

Arne

Re: Is there a simpler way to map Hibernate?

<0626d57c-7e93-42dc-a807-8310b7badc7cn@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=297&group=comp.lang.java.programmer#297

  copy link   Newsgroups: comp.lang.java.programmer
X-Received: by 2002:a05:622a:199e:b0:412:2bb3:8f28 with SMTP id u30-20020a05622a199e00b004122bb38f28mr73217qtc.0.1693597701755;
Fri, 01 Sep 2023 12:48:21 -0700 (PDT)
X-Received: by 2002:a25:aaec:0:b0:d4c:fe4d:31ff with SMTP id
t99-20020a25aaec000000b00d4cfe4d31ffmr103095ybi.8.1693597701531; Fri, 01 Sep
2023 12:48:21 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.java.programmer
Date: Fri, 1 Sep 2023 12:48:21 -0700 (PDT)
In-Reply-To: <ucspf7$3ppii$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=98.237.40.232; posting-account=2czF5goAAAD4GBMPIGV4KcD2K4PhoB_H
NNTP-Posting-Host: 98.237.40.232
References: <015e1e01-2e15-49bf-ae5e-07470e4e3d2bn@googlegroups.com>
<ucr57u$3fa1g$1@dont-email.me> <c7dbfc66-c143-45f0-8501-50d9aa90e3b2n@googlegroups.com>
<ucslb3$3p6nj$1@dont-email.me> <f0746a5b-9125-4055-b2a4-de230c621f6cn@googlegroups.com>
<ucsnkr$3pftv$1@dont-email.me> <69105518-21d7-468c-9774-e9ffb497677fn@googlegroups.com>
<ucspf7$3ppii$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <0626d57c-7e93-42dc-a807-8310b7badc7cn@googlegroups.com>
Subject: Re: Is there a simpler way to map Hibernate?
From: e.d.programmer@gmail.com (e.d.pro...@gmail.com)
Injection-Date: Fri, 01 Sep 2023 19:48:21 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1823
 by: e.d.pro...@gmail.com - Fri, 1 Sep 2023 19:48 UTC

> but you could try with:
>
> <exclude-unlisted-classes>false</exclude-unlisted-classes>
>
> I am not an expert in the finer points of JPA, but I remember
> it as that false should work in Java EE context and that it
> is not guaranteed to work in SE context but usually does.
>
> Arne
I started trying to implement this, didn't get time to test today, I'll let you know.

Re: Is there a simpler way to map Hibernate?

<74cf0893-49c0-46dc-8381-92244f60bde1n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=298&group=comp.lang.java.programmer#298

  copy link   Newsgroups: comp.lang.java.programmer
X-Received: by 2002:a05:620a:4384:b0:770:7460:c426 with SMTP id a4-20020a05620a438400b007707460c426mr155566qkp.0.1693942486317;
Tue, 05 Sep 2023 12:34:46 -0700 (PDT)
X-Received: by 2002:a17:90a:3d45:b0:269:84ec:7140 with SMTP id
o5-20020a17090a3d4500b0026984ec7140mr3398034pjf.2.1693942485809; Tue, 05 Sep
2023 12:34:45 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.java.programmer
Date: Tue, 5 Sep 2023 12:34:45 -0700 (PDT)
In-Reply-To: <ucspf7$3ppii$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=98.237.40.232; posting-account=2czF5goAAAD4GBMPIGV4KcD2K4PhoB_H
NNTP-Posting-Host: 98.237.40.232
References: <015e1e01-2e15-49bf-ae5e-07470e4e3d2bn@googlegroups.com>
<ucr57u$3fa1g$1@dont-email.me> <c7dbfc66-c143-45f0-8501-50d9aa90e3b2n@googlegroups.com>
<ucslb3$3p6nj$1@dont-email.me> <f0746a5b-9125-4055-b2a4-de230c621f6cn@googlegroups.com>
<ucsnkr$3pftv$1@dont-email.me> <69105518-21d7-468c-9774-e9ffb497677fn@googlegroups.com>
<ucspf7$3ppii$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <74cf0893-49c0-46dc-8381-92244f60bde1n@googlegroups.com>
Subject: Re: Is there a simpler way to map Hibernate?
From: e.d.programmer@gmail.com (e.d.pro...@gmail.com)
Injection-Date: Tue, 05 Sep 2023 19:34:46 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2845
 by: e.d.pro...@gmail.com - Tue, 5 Sep 2023 19:34 UTC

> Yes. Basically:
>
> EntityManagerFactory emf = Persistence.createEntityManagerFactory(confnam);
> EntityManager em = emf.createEntityManager();
>
> instead of:
>
> SessionFactory sf = new Configuration().configure(new
> File(conffile)).buildSessionFactory();
> Session s = sf.openSession();
....
>
> Arne

This is confusing. I've been implementing the openSession using try-with-resources.
org.hibernate.Session extends javax.persistence.EntityManager (I'm using Hibernate 5x since 6x requires newer Java, stuck using Java 8 for now) as well as Autocloseable.
EntityManager is not autocloseable, though if I'm reading this right, the first thread I found on stackoverflow suggests closing it after every use unless you're working with very small data.
If I'm creating the EntityManager directly instead of the Session, should I create my own wrapper to make it auto-closeable? Is there a good use case for not closing it? It causes memory leaks if you don't close it when you're done with it unless you're re-using the same one instead of creating a new one each time? I assume they can still be chained, like I create one in a DAO to access one DTO and while it's open I call a method of a different DAO to access a different DTO and it creates it's own EntityManager?

Re: Is there a simpler way to map Hibernate?

<udlo4l$otip$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=299&group=comp.lang.java.programmer#299

  copy link   Newsgroups: comp.lang.java.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: arne@vajhoej.dk (Arne Vajhøj)
Newsgroups: comp.lang.java.programmer
Subject: Re: Is there a simpler way to map Hibernate?
Date: Sun, 10 Sep 2023 20:48:21 -0400
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <udlo4l$otip$1@dont-email.me>
References: <015e1e01-2e15-49bf-ae5e-07470e4e3d2bn@googlegroups.com>
<ucr57u$3fa1g$1@dont-email.me>
<c7dbfc66-c143-45f0-8501-50d9aa90e3b2n@googlegroups.com>
<ucslb3$3p6nj$1@dont-email.me>
<f0746a5b-9125-4055-b2a4-de230c621f6cn@googlegroups.com>
<ucsnkr$3pftv$1@dont-email.me>
<69105518-21d7-468c-9774-e9ffb497677fn@googlegroups.com>
<ucspf7$3ppii$1@dont-email.me>
<74cf0893-49c0-46dc-8381-92244f60bde1n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 11 Sep 2023 00:48:22 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="28ca6c9d5c554b433b19a6c64ccf821f";
logging-data="816729"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19nWosKrb7Qg1m+IL0B1mjBgtLI+pdXF9Q="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:r0KhJBzOBGrojh+kC0oz53jyL9c=
In-Reply-To: <74cf0893-49c0-46dc-8381-92244f60bde1n@googlegroups.com>
Content-Language: en-US
 by: Arne Vajhøj - Mon, 11 Sep 2023 00:48 UTC

On 9/5/2023 3:34 PM, e.d.pro...@gmail.com wrote:
>> Yes. Basically:
>>
>> EntityManagerFactory emf =
>> Persistence.createEntityManagerFactory(confnam); EntityManager em =
>> emf.createEntityManager();
>>
>> instead of:
>>
>> SessionFactory sf = new Configuration().configure(new
>> File(conffile)).buildSessionFactory(); Session s =
>> sf.openSession();
> ...
>
> This is confusing. I've been implementing the openSession using
> try-with-resources. org.hibernate.Session extends
> javax.persistence.EntityManager (I'm using Hibernate 5x since 6x
> requires newer Java, stuck using Java 8 for now) as well as
> Autocloseable. EntityManager is not autocloseable,

If Session extends EntityManager you should be able to
use the JPA methods on Session and just use Session auto closeable
feature.

Arne

Re: Is there a simpler way to map Hibernate?

<4d753bdf-e14f-416b-97c2-254de83c55b7n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=300&group=comp.lang.java.programmer#300

  copy link   Newsgroups: comp.lang.java.programmer
X-Received: by 2002:ac8:7dc3:0:b0:412:14a0:448e with SMTP id c3-20020ac87dc3000000b0041214a0448emr206957qte.1.1694431167205;
Mon, 11 Sep 2023 04:19:27 -0700 (PDT)
X-Received: by 2002:a05:690c:f08:b0:586:e91a:46c2 with SMTP id
dc8-20020a05690c0f0800b00586e91a46c2mr456433ywb.4.1694431166806; Mon, 11 Sep
2023 04:19:26 -0700 (PDT)
Path: i2pn2.org!rocksolid2!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.java.programmer
Date: Mon, 11 Sep 2023 04:19:26 -0700 (PDT)
In-Reply-To: <udlo4l$otip$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=98.237.40.232; posting-account=2czF5goAAAD4GBMPIGV4KcD2K4PhoB_H
NNTP-Posting-Host: 98.237.40.232
References: <015e1e01-2e15-49bf-ae5e-07470e4e3d2bn@googlegroups.com>
<ucr57u$3fa1g$1@dont-email.me> <c7dbfc66-c143-45f0-8501-50d9aa90e3b2n@googlegroups.com>
<ucslb3$3p6nj$1@dont-email.me> <f0746a5b-9125-4055-b2a4-de230c621f6cn@googlegroups.com>
<ucsnkr$3pftv$1@dont-email.me> <69105518-21d7-468c-9774-e9ffb497677fn@googlegroups.com>
<ucspf7$3ppii$1@dont-email.me> <74cf0893-49c0-46dc-8381-92244f60bde1n@googlegroups.com>
<udlo4l$otip$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <4d753bdf-e14f-416b-97c2-254de83c55b7n@googlegroups.com>
Subject: Re: Is there a simpler way to map Hibernate?
From: e.d.programmer@gmail.com (e.d.pro...@gmail.com)
Injection-Date: Mon, 11 Sep 2023 11:19:27 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2139
 by: e.d.pro...@gmail.com - Mon, 11 Sep 2023 11:19 UTC

> > This is confusing. I've been implementing the openSession using
> > try-with-resources. org.hibernate.Session extends
> > javax.persistence.EntityManager (I'm using Hibernate 5x since 6x
> > requires newer Java, stuck using Java 8 for now) as well as
> > Autocloseable. EntityManager is not autocloseable,
> If Session extends EntityManager you should be able to
> use the JPA methods on Session and just use Session auto closeable
> feature.
>
> Arne

So just use EntityManagerFactory instead of SessionFactory, then just call .unwrap(Session.class) and nothing needs to change but the factory?

Re: Is there a simpler way to map Hibernate?

<467de546-1da2-4943-83f8-4dd760f7c136n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=301&group=comp.lang.java.programmer#301

  copy link   Newsgroups: comp.lang.java.programmer
X-Received: by 2002:a05:622a:1822:b0:412:1e76:f3e1 with SMTP id t34-20020a05622a182200b004121e76f3e1mr182162qtc.3.1694435006159;
Mon, 11 Sep 2023 05:23:26 -0700 (PDT)
X-Received: by 2002:a81:ae5b:0:b0:56f:f62b:7a11 with SMTP id
g27-20020a81ae5b000000b0056ff62b7a11mr213486ywk.8.1694435005745; Mon, 11 Sep
2023 05:23:25 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.java.programmer
Date: Mon, 11 Sep 2023 05:23:25 -0700 (PDT)
In-Reply-To: <udlo4l$otip$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=98.237.40.232; posting-account=2czF5goAAAD4GBMPIGV4KcD2K4PhoB_H
NNTP-Posting-Host: 98.237.40.232
References: <015e1e01-2e15-49bf-ae5e-07470e4e3d2bn@googlegroups.com>
<ucr57u$3fa1g$1@dont-email.me> <c7dbfc66-c143-45f0-8501-50d9aa90e3b2n@googlegroups.com>
<ucslb3$3p6nj$1@dont-email.me> <f0746a5b-9125-4055-b2a4-de230c621f6cn@googlegroups.com>
<ucsnkr$3pftv$1@dont-email.me> <69105518-21d7-468c-9774-e9ffb497677fn@googlegroups.com>
<ucspf7$3ppii$1@dont-email.me> <74cf0893-49c0-46dc-8381-92244f60bde1n@googlegroups.com>
<udlo4l$otip$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <467de546-1da2-4943-83f8-4dd760f7c136n@googlegroups.com>
Subject: Re: Is there a simpler way to map Hibernate?
From: e.d.programmer@gmail.com (e.d.pro...@gmail.com)
Injection-Date: Mon, 11 Sep 2023 12:23:26 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3050
 by: e.d.pro...@gmail.com - Mon, 11 Sep 2023 12:23 UTC

> If Session extends EntityManager you should be able to
> use the JPA methods on Session and just use Session auto closeable
> feature.
>
> Arne

So I'm trying this.
I deleted hibernate.cfg.xml. I created src/main/resources/META-INF/hibernate.xml.
My hibernate.xml has a persistence-unit with the <exclude-unlisted-classes>false and 5 properties defining the JDBC connection, no class specific mappings.
I read on one S/O that the unwrap(Session.class) should return a Session, it didn't.
We have a final class with a private static factory. I changed that factory from the hibernate factory to EntityManagerFactory.
Now it has a static method I changed to:
public static Session getHibernateSession() {
if (factory == null) {
factory = Persistence.createEntityManagerFactory("mypersistenceunit.jpa");
}
Object delegate = factory.createEntityManager().getDelegate();
if (delegate instanceof Session) {
return (Session) delegate;
}
return factory.unwrap(Session.class);
} We call this method from try-with-resources. This is working. The next apparent question is do we want to be referencing org.hibernate.Session? One site says use EntityManager to keep it generic because there are framework alternatives to Hibernate ("like EclipseLink or TopLink"?). It seems Hibernate is supposed to be "under the hood" so we have few if any references to it outside of the pom and persistence.xml.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor