Dave12345
Dave12345
JCHJava Community | Help. Code. Learn.
Created by Dave12345 on 12/26/2024 in #java-help
JUnit succeeds when run as "debug as junit test" but fails as "debug as gradle test".
but that's just db setup
31 replies
JCHJava Community | Help. Code. Learn.
Created by Dave12345 on 12/26/2024 in #java-help
JUnit succeeds when run as "debug as junit test" but fails as "debug as gradle test".
my config is in hibernate.properties
31 replies
JCHJava Community | Help. Code. Learn.
Created by Dave12345 on 12/26/2024 in #java-help
JUnit succeeds when run as "debug as junit test" but fails as "debug as gradle test".
there's no CI here - just me experimenting with stuff on my laptop. from the junit class, which has two tests, i can debug as junit and both tests pass. one test literally is just assertequals(1,1) to check I was running tests properly from gradle. Running just that tests (with the other commented out) I can run it via junit and gradle (gradle both from within eclipse and from the command line). Persistance.xml:
<persistence
version="2.2"
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd">

<persistence-unit name="my-persistence-unit"
transaction-type="RESOURCE_LOCAL">
<description>descr</description>
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
</persistence-unit>

</persistence>
<persistence
version="2.2"
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd">

<persistence-unit name="my-persistence-unit"
transaction-type="RESOURCE_LOCAL">
<description>descr</description>
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
</persistence-unit>

</persistence>
31 replies
JCHJava Community | Help. Code. Learn.
Created by Dave12345 on 12/26/2024 in #java-help
JUnit succeeds when run as "debug as junit test" but fails as "debug as gradle test".
(I tried copying stuff there earlier but it made no diff)
31 replies
JCHJava Community | Help. Code. Learn.
Created by Dave12345 on 12/26/2024 in #java-help
JUnit succeeds when run as "debug as junit test" but fails as "debug as gradle test".
there is nothing at all in test/resources
31 replies
JCHJava Community | Help. Code. Learn.
Created by Dave12345 on 12/26/2024 in #java-help
JUnit succeeds when run as "debug as junit test" but fails as "debug as gradle test".
I think tests can see stuff in main/resources so it's not that
31 replies
JCHJava Community | Help. Code. Learn.
Created by Dave12345 on 12/26/2024 in #java-help
JUnit succeeds when run as "debug as junit test" but fails as "debug as gradle test".
I mean, I'm guessing, though, that this is an example of a wider problem, right? If any code works in junit but not via gradlew then I'm missing some setup/config code, right?
31 replies
JCHJava Community | Help. Code. Learn.
Created by Dave12345 on 12/26/2024 in #java-help
JUnit succeeds when run as "debug as junit test" but fails as "debug as gradle test".
org.hibernate.internal.SessionImpl.firePersist(PersistEvent) L760: fastSessionServices.eventListenerGroup_PERSIST .fireEventOnEachListener( event, PersistEventListener::onPersist ); MappingException
31 replies
JCHJava Community | Help. Code. Learn.
Created by Dave12345 on 12/26/2024 in #java-help
JUnit succeeds when run as "debug as junit test" but fails as "debug as gradle test".
Not sure. I mean, I can try anything you suggest! I can run the test from within eclipse if that's easier.
31 replies
JCHJava Community | Help. Code. Learn.
Created by Dave12345 on 12/26/2024 in #java-help
JUnit succeeds when run as "debug as junit test" but fails as "debug as gradle test".
31 replies
JCHJava Community | Help. Code. Learn.
Created by Dave12345 on 12/26/2024 in #java-help
JUnit succeeds when run as "debug as junit test" but fails as "debug as gradle test".
It was created as a gradle project. I can clean/build just fine. I can run it on the command line by copying the command line params from eclipse.
What logs should I be looking for? I've added log4j logging which is how I know about this error.
31 replies
JCHJava Community | Help. Code. Learn.
Created by Dave12345 on 12/22/2024 in #java-help
Guice with empty Module
ok thanks for your help!
25 replies
JCHJava Community | Help. Code. Learn.
Created by Dave12345 on 12/22/2024 in #java-help
Guice with empty Module
that's my instinctual preference too. I'm using java at lot at work and it's a huge project with every technology in the world in it. I'm spending a little time at home using some of the tech but in a much smaller test project and trying to learn how to do stuff very cleanly and properly. At work there's some crazy injector class which is populated from multiple modules and service loaders and god knows where else so you can inject anything anywhere so you never need to know which module is used etc. So I've never had to actually create a module or write a .createInjector etc - it's already done somewhere!
25 replies
JCHJava Community | Help. Code. Learn.
Created by Dave12345 on 12/22/2024 in #java-help
Guice with empty Module
ok, i'll give that a go - thanks!
25 replies
JCHJava Community | Help. Code. Learn.
Created by Dave12345 on 12/22/2024 in #java-help
Guice with empty Module
Usually it's not empty as you need to bind an implementation to an interface
25 replies
JCHJava Community | Help. Code. Learn.
Created by Dave12345 on 12/22/2024 in #java-help
Guice with empty Module
Yes. "my Module (extending AbstractModule) is empty". I'm probably phrasing it wrongly?
25 replies
JCHJava Community | Help. Code. Learn.
Created by Dave12345 on 12/22/2024 in #java-help
Guice with empty Module
Below is the relevant code. To be clear, this is a "best practice" type question. Like I said up front, this works. There's nothing that shows me "empty bindings". I simply have a (what looks to me at least) pointless empty module and I'm wondering if there's a way to do away with it.
public class HibernateModule extends AbstractModule {

}


public class Library {
public static void main(String[] args) {
Injector injector = Guice.createInjector(new HibernateModule());
HibernateSandbox hs = injector.getInstance(HibernateSandbox.class);
hs.test();
}
}

public class HibernateSandbox {
@Inject
EntityManagerProvider emp;

public void test() {
EntityManager em = emp.get();
if (em == null) {
System.out.println("Couldn't get entitymanager");
return;
}
Etc etc
public class HibernateModule extends AbstractModule {

}


public class Library {
public static void main(String[] args) {
Injector injector = Guice.createInjector(new HibernateModule());
HibernateSandbox hs = injector.getInstance(HibernateSandbox.class);
hs.test();
}
}

public class HibernateSandbox {
@Inject
EntityManagerProvider emp;

public void test() {
EntityManager em = emp.get();
if (em == null) {
System.out.println("Couldn't get entitymanager");
return;
}
Etc etc
25 replies
JCHJava Community | Help. Code. Learn.
Created by Dave12345 on 12/22/2024 in #java-help
Guice with empty Module
There's no bindings defined in it.
25 replies