[JBoss JIRA] (WFLY-13341) Substitution of environment / system properties for microprofile-opentracing-smallrye extension
by Brian Stansberry (Jira)
[ https://issues.redhat.com/browse/WFLY-13341?page=com.atlassian.jira.plugi... ]
Brian Stansberry updated WFLY-13341:
------------------------------------
Issue Type: Bug (was: Feature Request)
I don't see this as a feature request. Not supporting an expression on an attribute whose value isn't a capability reference, class name or module name should be regarded as a bug unless there is a strong case why it has to be that way. And if there was such a case, eliminating that case would be an Enhancement, not a Feature. The fact that attributes support expressions is a WildFly feature in place since JBoss AS 7.0. Making that existing feature work isn't a new feature, i.e. something that requires the analysis test planning and documentation that we do for features.
> Substitution of environment / system properties for microprofile-opentracing-smallrye extension
> -----------------------------------------------------------------------------------------------
>
> Key: WFLY-13341
> URL: https://issues.redhat.com/browse/WFLY-13341
> Project: WildFly
> Issue Type: Bug
> Components: MP OpenTracing
> Affects Versions: 19.0.0.Final
> Reporter: Yeray Borges Santana
> Assignee: Emmanuel Hugonnet
> Priority: Major
>
> I would like to able to configure the microprofile-opentracing-smallrye extension in wildfly 19 with substituted variables (environment or system).
> When I try this it seems the values are not resolved, for example
> {code:xml}
> <subsystem xmlns="urn:wildfly:microprofile-opentracing-smallrye:2.0" default-tracer="jaeger">
> <jaeger-tracer name="jaeger">
> <tags>
> <property name="env" value="${env.ENV}"/>
> <property name="user" value="joe"/>
> </tags>
> <sampler-configuration sampler-type="ratelimiting" sampler-param="1.0"/>
> <sender-configuration sender-endpoint="http://${JAEGER_AGENT_HOST}:14268/api/traces"/>
> </jaeger-tracer>
> </subsystem>
> {code}
> results in:
> {noformat}
> 2020-03-29 15:17:49,448 ERROR [jaeger.RemoteReporter-QueueProcessor] [] [] [] [] [] (io.jaegertracing.internal.reporters
> .RemoteReporter) QueueProcessor error:: java.lang.RuntimeException: java.net.URISyntaxException: Illegal character in au
> thority at index 7: http://${jaeger_agent_host}:14268/
> at com.squareup.okhttp3//okhttp3.HttpUrl.uri(HttpUrl.java:385)
> at com.squareup.okhttp3//okhttp3.internal.connection.RouteSelector.resetNextProxy(RouteSelector.java:129)
> at com.squareup.okhttp3//okhttp3.internal.connection.RouteSelector.<init>(RouteSelector.java:63)
> at com.squareup.okhttp3//okhttp3.internal.connection.StreamAllocation.<init>(StreamAllocation.java:101)
> {noformat}
--
This message was sent by Atlassian Jira
(v7.13.8#713008)
4 years, 6 months
[JBoss JIRA] (WFLY-13339) Remove transitive dependencies from MP OpenAPI TCKs
by Jan Stourac (Jira)
[ https://issues.redhat.com/browse/WFLY-13339?page=com.atlassian.jira.plugi... ]
Jan Stourac updated WFLY-13339:
-------------------------------
Component/s: Test Suite
> Remove transitive dependencies from MP OpenAPI TCKs
> ---------------------------------------------------
>
> Key: WFLY-13339
> URL: https://issues.redhat.com/browse/WFLY-13339
> Project: WildFly
> Issue Type: Bug
> Components: MP OpenAPI, Test Suite
> Affects Versions: 19.0.0.Final
> Reporter: Jan Stourac
> Assignee: Paul Ferraro
> Priority: Major
>
> In MP OpenAPI TCK integration tests module, there is defined dependency 'microprofile-openapi-tck', which broughts in another set of transition dependencies which are not required for execution of these tests in WildFly testsuite.
> We should avoid transitive dependencies and explicitely define required ones in WildFly in order to avoid unwanted dependencies in our deptree and to keep version consistency.
--
This message was sent by Atlassian Jira
(v7.13.8#713008)
4 years, 6 months
[JBoss JIRA] (HIBERNATE-174) NullPointerException at org.hibernate.boot.archive.scan.spi.ClassFileArchiveEntryHandler.toClassDescriptor - Hibernate 6.0.0.Alpha4
by Victor Williams Stafusa da Silva (Jira)
[ https://issues.redhat.com/browse/HIBERNATE-174?page=com.atlassian.jira.pl... ]
Victor Williams Stafusa da Silva updated HIBERNATE-174:
-------------------------------------------------------
Description:
This code works fine in Hibernate 5.4.13.Final, but gives a NullPointerException at Hibernate 6.0.0.Alpha4:
Test file:
{code:title=Hbug.java|borderStyle=solid}
package com.example;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import javax.persistence.spi.PersistenceProvider;
import org.hibernate.SessionFactory;
import org.hibernate.jpa.HibernatePersistenceProvider;
/**
* @author Victor Williams Stafusa da Silva
*/
public class Hbug {
public static void main(String[] args) throws Exception {
Map<String, String> props = new HashMap<>();
props.put("javax.persistence.jdbc.user", "sa");
props.put("javax.persistence.jdbc.password", "");
props.put("javax.persistence.jdbc.url", "jdbc:hsqldb:mem:test1");
props.put("hibernate.hbm2ddl.import_files_sql_extractor", "org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor");
props.put("javax.persistence.schema-generation.database.action", "drop-and-create");
PersistenceProvider pp = new HibernatePersistenceProvider();
var spui = new SimplePersistenceUnitInfo(
Optional.empty(),
HibernatePersistenceProvider.class,
"test-1",
Set.of(Fruit.class),
props);
var emf = pp.createContainerEntityManagerFactory(spui, props);
if (!(emf instanceof SessionFactory)) throw new Exception("Bad EMF");
}
}
{code}
Utilitary class used by the above one:
{code:title=SimplePersistenceUnitInfo.java|borderStyle=solid}
package com.example;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.stream.Collectors;
import javax.persistence.SharedCacheMode;
import javax.persistence.ValidationMode;
import javax.persistence.spi.ClassTransformer;
import javax.persistence.spi.PersistenceProvider;
import javax.persistence.spi.PersistenceUnitInfo;
import javax.persistence.spi.PersistenceUnitTransactionType;
import javax.sql.DataSource;
/**
* @author Victor Williams Stafusa da Silva
*/
public final class SimplePersistenceUnitInfo implements PersistenceUnitInfo {
private final Optional<URL> url;
private final Class<? extends PersistenceProvider> providerClass;
private final String persistenceUnitName;
private final List<String> classes;
private final Map<String, String> properties;
public SimplePersistenceUnitInfo(
/*@NonNull*/ Optional<URL> url,
/*@NonNull*/ Class<? extends PersistenceProvider> providerClass,
/*@NonNull*/ String persistenceUnitName,
/*@NonNull*/ Collection<Class<?>> classes,
/*@NonNull*/ Map<String, String> properties)
{
this.url = url;
this.providerClass = providerClass;
this.persistenceUnitName = persistenceUnitName;
this.classes = classes.stream().map(Class::getName).collect(Collectors.toList());
this.properties = new HashMap<>();
this.properties.putAll(properties);
}
@Override
public String getPersistenceUnitName() {
return persistenceUnitName;
}
@Override
public String getPersistenceProviderClassName() {
return providerClass.getName();
}
@Override
public PersistenceUnitTransactionType getTransactionType() {
return PersistenceUnitTransactionType.RESOURCE_LOCAL;
}
@Override
//@Nullable
public DataSource getJtaDataSource() {
return null;
}
@Override
//@Nullable
public DataSource getNonJtaDataSource() {
return null;
}
@Override
public List<String> getMappingFileNames() {
return Collections.emptyList();
}
@Override
public List<URL> getJarFileUrls() {
try {
return Collections.list(this.getClass().getClassLoader().getResources(""));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
//@Nullable
@Override
public URL getPersistenceUnitRootUrl() {
return url.orElse(null);
}
@Override
public List<String> getManagedClassNames() {
return Collections.unmodifiableList(classes);
}
@Override
public boolean excludeUnlistedClasses() {
return false;
}
@Override
public SharedCacheMode getSharedCacheMode() {
return SharedCacheMode.UNSPECIFIED;
}
@Override
public ValidationMode getValidationMode() {
return ValidationMode.AUTO;
}
@Override
public Properties getProperties() {
Properties p = new Properties();
p.putAll(properties);
return p;
}
@Override
public String getPersistenceXMLSchemaVersion() {
return "2.2";
}
@Override
//@Nullable
public ClassLoader getClassLoader() {
return Thread.currentThread().getContextClassLoader();
}
@Override
public void addTransformer(ClassTransformer transformer) {
}
@Override
//@Nullable
public ClassLoader getNewTempClassLoader() {
return null;
}
}
{code}
Sample entity class:
{code:title=Fruit.java|borderStyle=solid}
package com.example;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
/**
* @author Victor Williams Stafusa da Silva
*/
@Entity
@Table(name = "fruits")
public class Fruit implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String name;
private String color;
public Fruit() {}
public Fruit(String name, String color) {
this.name = name;
this.color = color;
}
public String getName() {
return name;
}
public String getColor() {
return color;
}
}
{code}
Gradle script to build that:
{code:title=build.gradle|borderStyle=solid}
apply plugin: 'java'
apply plugin: 'application'
group = 'com.example'
mainClassName = 'com.example.Hbug'
repositories {
jcenter()
}
dependencies {
implementation 'org.hsqldb:hsqldb:2.5.0'
//implementation 'org.hibernate:hibernate-core:5.4.13.Final'
implementation 'org.hibernate.orm:hibernate-core:6.0.0.Alpha4'
}
{code}
Run the code above and a NullPointerException will be throw (with Hibernate 6.0.0.Alpha4). However, if the gradle file is changed to use Hibernate 5.4.13 (uncomment that line and comment the one for 6.0.0.Alpha4), then the code works as expected.
Here is the output, including the stack trace:
{code:title=output|borderStyle=solid}
Apr 07, 2020 7:19:53 AM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
INFO: HHH000204: Processing PersistenceUnitInfo [name: test-1]
Apr 07, 2020 7:19:54 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {6.0.0.Alpha4}
Apr 07, 2020 7:19:54 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
Exception in thread "main" java.lang.NullPointerException
at org.hibernate.boot.archive.scan.spi.ClassFileArchiveEntryHandler.toClassDescriptor(ClassFileArchiveEntryHandler.java:84)
at org.hibernate.boot.archive.scan.spi.ClassFileArchiveEntryHandler.toClassDescriptor(ClassFileArchiveEntryHandler.java:67)
at org.hibernate.boot.archive.scan.spi.ClassFileArchiveEntryHandler.handleEntry(ClassFileArchiveEntryHandler.java:53)
at org.hibernate.boot.archive.internal.JarFileBasedArchiveDescriptor.visitArchive(JarFileBasedArchiveDescriptor.java:147)
at org.hibernate.boot.archive.internal.JarProtocolArchiveDescriptor.visitArchive(JarProtocolArchiveDescriptor.java:59)
at org.hibernate.boot.archive.scan.spi.AbstractScannerImpl.scan(AbstractScannerImpl.java:40)
at org.hibernate.boot.model.process.internal.ScanningCoordinator.coordinateScan(ScanningCoordinator.java:74)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.prepare(MetadataBuildingProcess.java:97)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:243)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:169)
at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:32)
at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:89)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:166)
at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:141)
at com.example.Hbug.main(Hbug.java:31)
{code}
P.S.: I'm running this using and compiling this using Java 13.0.2.
was:
This code works fine in Hibernate 5.4.13.Final, but gives a NullPointerException at Hibernate 6.0.0.Alpha4:
Test file:
{code:title=Hbug.java|borderStyle=solid}
package com.example;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import javax.persistence.spi.PersistenceProvider;
import org.hibernate.SessionFactory;
import org.hibernate.jpa.HibernatePersistenceProvider;
/**
* @author Victor Williams Stafusa da Silva
*/
public class Hbug {
public static void main(String[] args) throws Exception {
Map<String, String> props = new HashMap<>();
props.put("javax.persistence.jdbc.user", "sa");
props.put("javax.persistence.jdbc.password", "");
props.put("javax.persistence.jdbc.url", "jdbc:hsqldb:mem:test1");
props.put("hibernate.hbm2ddl.import_files_sql_extractor", "org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor");
props.put("javax.persistence.schema-generation.database.action", "drop-and-create");
PersistenceProvider pp = new HibernatePersistenceProvider();
var spui = new SimplePersistenceUnitInfo(
Optional.empty(),
HibernatePersistenceProvider.class,
"test-1",
Set.of(Fruit.class),
props);
var emf = pp.createContainerEntityManagerFactory(spui, props);
if (!(emf instanceof SessionFactory)) throw new Exception("Bad EMF");
}
}
{code}
Utilitary class used by the above one:
{code:title=SimplePersistenceUnitInfo.java|borderStyle=solid}
package com.example;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.stream.Collectors;
import javax.persistence.SharedCacheMode;
import javax.persistence.ValidationMode;
import javax.persistence.spi.ClassTransformer;
import javax.persistence.spi.PersistenceProvider;
import javax.persistence.spi.PersistenceUnitInfo;
import javax.persistence.spi.PersistenceUnitTransactionType;
import javax.sql.DataSource;
/**
* @author Victor Williams Stafusa da Silva
*/
public final class SimplePersistenceUnitInfo implements PersistenceUnitInfo {
private final Optional<URL> url;
private final Class<? extends PersistenceProvider> providerClass;
private final String persistenceUnitName;
private final List<String> classes;
private final Map<String, String> properties;
public SimplePersistenceUnitInfo(
/*@NonNull*/ Optional<URL> url,
/*@NonNull*/ Class<? extends PersistenceProvider> providerClass,
/*@NonNull*/ String persistenceUnitName,
/*@NonNull*/ Collection<Class<?>> classes,
/*@NonNull*/ Map<String, String> properties)
{
this.url = url;
this.providerClass = providerClass;
this.persistenceUnitName = persistenceUnitName;
this.classes = classes.stream().map(Class::getName).collect(Collectors.toList());
this.properties = new HashMap<>();
this.properties.putAll(properties);
}
@Override
public String getPersistenceUnitName() {
return persistenceUnitName;
}
@Override
public String getPersistenceProviderClassName() {
return providerClass.getName();
}
@Override
public PersistenceUnitTransactionType getTransactionType() {
return PersistenceUnitTransactionType.RESOURCE_LOCAL;
}
@Override
//@Nullable
public DataSource getJtaDataSource() {
return null;
}
@Override
//@Nullable
public DataSource getNonJtaDataSource() {
return null;
}
@Override
public List<String> getMappingFileNames() {
return Collections.emptyList();
}
@Override
public List<URL> getJarFileUrls() {
try {
return Collections.list(this.getClass().getClassLoader().getResources(""));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
//@Nullable
@Override
public URL getPersistenceUnitRootUrl() {
return url.orElse(null);
}
@Override
public List<String> getManagedClassNames() {
return Collections.unmodifiableList(classes);
}
@Override
public boolean excludeUnlistedClasses() {
return false;
}
@Override
public SharedCacheMode getSharedCacheMode() {
return SharedCacheMode.UNSPECIFIED;
}
@Override
public ValidationMode getValidationMode() {
return ValidationMode.AUTO;
}
@Override
public Properties getProperties() {
Properties p = new Properties();
p.putAll(properties);
return p;
}
@Override
public String getPersistenceXMLSchemaVersion() {
return "2.2";
}
@Override
//@Nullable
public ClassLoader getClassLoader() {
return Thread.currentThread().getContextClassLoader();
}
@Override
public void addTransformer(ClassTransformer transformer) {
}
@Override
//@Nullable
public ClassLoader getNewTempClassLoader() {
return null;
}
}
{code}
Sample entity class:
{code:title=Fruit.java|borderStyle=solid}
package com.example;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
/**
* @author Victor Williams Stafusa da Silva
*/
@Entity
@Table(name = "fruits")
public class Fruit implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String name;
private String color;
public Fruit() {}
public Fruit(String name, String color) {
this.name = name;
this.color = color;
}
public String getName() {
return name;
}
public String getColor() {
return color;
}
}
{code}
Gradle script to build that:
{code:title=build.gradle|borderStyle=solid}
apply plugin: 'java'
apply plugin: 'application'
group = 'com.example'
mainClassName = 'com.example.Hbug'
repositories {
jcenter()
}
dependencies {
implementation 'org.hsqldb:hsqldb:2.5.0'
//implementation 'org.hibernate:hibernate-core:5.4.13.Final'
implementation 'org.hibernate.orm:hibernate-core:6.0.0.Alpha4'
}
{code}
Run the code above and a NullPointerException will be throw (with Hibernate 6.0.0.Alpha4). However, if the gradle file is changed to use Hibernate 5.4.13 (uncomment that line and comment the one for 6.0.0.Alpha4), then the code works as expected.
Here is the output, including the stack trace:
{code:title=output|borderStyle=solid}
Apr 07, 2020 7:19:53 AM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
INFO: HHH000204: Processing PersistenceUnitInfo [name: test-1]
Apr 07, 2020 7:19:54 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {6.0.0.Alpha4}
Apr 07, 2020 7:19:54 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
Exception in thread "main" java.lang.NullPointerException
at org.hibernate.boot.archive.scan.spi.ClassFileArchiveEntryHandler.toClassDescriptor(ClassFileArchiveEntryHandler.java:84)
at org.hibernate.boot.archive.scan.spi.ClassFileArchiveEntryHandler.toClassDescriptor(ClassFileArchiveEntryHandler.java:67)
at org.hibernate.boot.archive.scan.spi.ClassFileArchiveEntryHandler.handleEntry(ClassFileArchiveEntryHandler.java:53)
at org.hibernate.boot.archive.internal.JarFileBasedArchiveDescriptor.visitArchive(JarFileBasedArchiveDescriptor.java:147)
at org.hibernate.boot.archive.internal.JarProtocolArchiveDescriptor.visitArchive(JarProtocolArchiveDescriptor.java:59)
at org.hibernate.boot.archive.scan.spi.AbstractScannerImpl.scan(AbstractScannerImpl.java:40)
at org.hibernate.boot.model.process.internal.ScanningCoordinator.coordinateScan(ScanningCoordinator.java:74)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.prepare(MetadataBuildingProcess.java:97)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:243)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:169)
at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:32)
at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:89)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:166)
at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:141)
at com.example.Hbug.main(Hbug.java:31)
{code}
P.S.: I'm running this using
> NullPointerException at org.hibernate.boot.archive.scan.spi.ClassFileArchiveEntryHandler.toClassDescriptor - Hibernate 6.0.0.Alpha4
> -----------------------------------------------------------------------------------------------------------------------------------
>
> Key: HIBERNATE-174
> URL: https://issues.redhat.com/browse/HIBERNATE-174
> Project: Hibernate Integration
> Issue Type: Bug
> Reporter: Victor Williams Stafusa da Silva
> Assignee: Steve Ebersole
> Priority: Critical
>
> This code works fine in Hibernate 5.4.13.Final, but gives a NullPointerException at Hibernate 6.0.0.Alpha4:
> Test file:
> {code:title=Hbug.java|borderStyle=solid}
> package com.example;
> import java.util.HashMap;
> import java.util.Map;
> import java.util.Optional;
> import java.util.Set;
> import javax.persistence.spi.PersistenceProvider;
> import org.hibernate.SessionFactory;
> import org.hibernate.jpa.HibernatePersistenceProvider;
> /**
> * @author Victor Williams Stafusa da Silva
> */
> public class Hbug {
> public static void main(String[] args) throws Exception {
> Map<String, String> props = new HashMap<>();
> props.put("javax.persistence.jdbc.user", "sa");
> props.put("javax.persistence.jdbc.password", "");
> props.put("javax.persistence.jdbc.url", "jdbc:hsqldb:mem:test1");
> props.put("hibernate.hbm2ddl.import_files_sql_extractor", "org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor");
> props.put("javax.persistence.schema-generation.database.action", "drop-and-create");
> PersistenceProvider pp = new HibernatePersistenceProvider();
> var spui = new SimplePersistenceUnitInfo(
> Optional.empty(),
> HibernatePersistenceProvider.class,
> "test-1",
> Set.of(Fruit.class),
> props);
> var emf = pp.createContainerEntityManagerFactory(spui, props);
> if (!(emf instanceof SessionFactory)) throw new Exception("Bad EMF");
> }
> }
> {code}
> Utilitary class used by the above one:
> {code:title=SimplePersistenceUnitInfo.java|borderStyle=solid}
> package com.example;
> import java.io.IOException;
> import java.io.UncheckedIOException;
> import java.net.URL;
> import java.util.Collection;
> import java.util.Collections;
> import java.util.HashMap;
> import java.util.List;
> import java.util.Map;
> import java.util.Optional;
> import java.util.Properties;
> import java.util.stream.Collectors;
> import javax.persistence.SharedCacheMode;
> import javax.persistence.ValidationMode;
> import javax.persistence.spi.ClassTransformer;
> import javax.persistence.spi.PersistenceProvider;
> import javax.persistence.spi.PersistenceUnitInfo;
> import javax.persistence.spi.PersistenceUnitTransactionType;
> import javax.sql.DataSource;
> /**
> * @author Victor Williams Stafusa da Silva
> */
> public final class SimplePersistenceUnitInfo implements PersistenceUnitInfo {
> private final Optional<URL> url;
> private final Class<? extends PersistenceProvider> providerClass;
> private final String persistenceUnitName;
> private final List<String> classes;
> private final Map<String, String> properties;
> public SimplePersistenceUnitInfo(
> /*@NonNull*/ Optional<URL> url,
> /*@NonNull*/ Class<? extends PersistenceProvider> providerClass,
> /*@NonNull*/ String persistenceUnitName,
> /*@NonNull*/ Collection<Class<?>> classes,
> /*@NonNull*/ Map<String, String> properties)
> {
> this.url = url;
> this.providerClass = providerClass;
> this.persistenceUnitName = persistenceUnitName;
> this.classes = classes.stream().map(Class::getName).collect(Collectors.toList());
> this.properties = new HashMap<>();
> this.properties.putAll(properties);
> }
> @Override
> public String getPersistenceUnitName() {
> return persistenceUnitName;
> }
> @Override
> public String getPersistenceProviderClassName() {
> return providerClass.getName();
> }
> @Override
> public PersistenceUnitTransactionType getTransactionType() {
> return PersistenceUnitTransactionType.RESOURCE_LOCAL;
> }
> @Override
> //@Nullable
> public DataSource getJtaDataSource() {
> return null;
> }
> @Override
> //@Nullable
> public DataSource getNonJtaDataSource() {
> return null;
> }
> @Override
> public List<String> getMappingFileNames() {
> return Collections.emptyList();
> }
> @Override
> public List<URL> getJarFileUrls() {
> try {
> return Collections.list(this.getClass().getClassLoader().getResources(""));
> } catch (IOException e) {
> throw new UncheckedIOException(e);
> }
> }
> //@Nullable
> @Override
> public URL getPersistenceUnitRootUrl() {
> return url.orElse(null);
> }
> @Override
> public List<String> getManagedClassNames() {
> return Collections.unmodifiableList(classes);
> }
> @Override
> public boolean excludeUnlistedClasses() {
> return false;
> }
> @Override
> public SharedCacheMode getSharedCacheMode() {
> return SharedCacheMode.UNSPECIFIED;
> }
> @Override
> public ValidationMode getValidationMode() {
> return ValidationMode.AUTO;
> }
> @Override
> public Properties getProperties() {
> Properties p = new Properties();
> p.putAll(properties);
> return p;
> }
> @Override
> public String getPersistenceXMLSchemaVersion() {
> return "2.2";
> }
> @Override
> //@Nullable
> public ClassLoader getClassLoader() {
> return Thread.currentThread().getContextClassLoader();
> }
> @Override
> public void addTransformer(ClassTransformer transformer) {
> }
> @Override
> //@Nullable
> public ClassLoader getNewTempClassLoader() {
> return null;
> }
> }
> {code}
> Sample entity class:
> {code:title=Fruit.java|borderStyle=solid}
> package com.example;
> import java.io.Serializable;
> import javax.persistence.Entity;
> import javax.persistence.GeneratedValue;
> import javax.persistence.GenerationType;
> import javax.persistence.Id;
> import javax.persistence.Table;
> /**
> * @author Victor Williams Stafusa da Silva
> */
> @Entity
> @Table(name = "fruits")
> public class Fruit implements Serializable {
> private static final long serialVersionUID = 1L;
> @Id
> @GeneratedValue(strategy = GenerationType.IDENTITY)
> private Integer id;
> private String name;
> private String color;
> public Fruit() {}
> public Fruit(String name, String color) {
> this.name = name;
> this.color = color;
> }
> public String getName() {
> return name;
> }
> public String getColor() {
> return color;
> }
> }
> {code}
> Gradle script to build that:
> {code:title=build.gradle|borderStyle=solid}
> apply plugin: 'java'
> apply plugin: 'application'
> group = 'com.example'
> mainClassName = 'com.example.Hbug'
> repositories {
> jcenter()
> }
> dependencies {
> implementation 'org.hsqldb:hsqldb:2.5.0'
> //implementation 'org.hibernate:hibernate-core:5.4.13.Final'
> implementation 'org.hibernate.orm:hibernate-core:6.0.0.Alpha4'
> }
> {code}
> Run the code above and a NullPointerException will be throw (with Hibernate 6.0.0.Alpha4). However, if the gradle file is changed to use Hibernate 5.4.13 (uncomment that line and comment the one for 6.0.0.Alpha4), then the code works as expected.
> Here is the output, including the stack trace:
> {code:title=output|borderStyle=solid}
> Apr 07, 2020 7:19:53 AM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
> INFO: HHH000204: Processing PersistenceUnitInfo [name: test-1]
> Apr 07, 2020 7:19:54 AM org.hibernate.Version logVersion
> INFO: HHH000412: Hibernate Core {6.0.0.Alpha4}
> Apr 07, 2020 7:19:54 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
> INFO: HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
> Exception in thread "main" java.lang.NullPointerException
> at org.hibernate.boot.archive.scan.spi.ClassFileArchiveEntryHandler.toClassDescriptor(ClassFileArchiveEntryHandler.java:84)
> at org.hibernate.boot.archive.scan.spi.ClassFileArchiveEntryHandler.toClassDescriptor(ClassFileArchiveEntryHandler.java:67)
> at org.hibernate.boot.archive.scan.spi.ClassFileArchiveEntryHandler.handleEntry(ClassFileArchiveEntryHandler.java:53)
> at org.hibernate.boot.archive.internal.JarFileBasedArchiveDescriptor.visitArchive(JarFileBasedArchiveDescriptor.java:147)
> at org.hibernate.boot.archive.internal.JarProtocolArchiveDescriptor.visitArchive(JarProtocolArchiveDescriptor.java:59)
> at org.hibernate.boot.archive.scan.spi.AbstractScannerImpl.scan(AbstractScannerImpl.java:40)
> at org.hibernate.boot.model.process.internal.ScanningCoordinator.coordinateScan(ScanningCoordinator.java:74)
> at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.prepare(MetadataBuildingProcess.java:97)
> at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:243)
> at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:169)
> at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:32)
> at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:89)
> at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:166)
> at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:141)
> at com.example.Hbug.main(Hbug.java:31)
> {code}
> P.S.: I'm running this using and compiling this using Java 13.0.2.
--
This message was sent by Atlassian Jira
(v7.13.8#713008)
4 years, 6 months
[JBoss JIRA] (HIBERNATE-174) NullPointerException at org.hibernate.boot.archive.scan.spi.ClassFileArchiveEntryHandler.toClassDescriptor - Hibernate 6.0.0.Alpha4
by Victor Williams Stafusa da Silva (Jira)
[ https://issues.redhat.com/browse/HIBERNATE-174?page=com.atlassian.jira.pl... ]
Victor Williams Stafusa da Silva updated HIBERNATE-174:
-------------------------------------------------------
Description:
This code works fine in Hibernate 5.4.13.Final, but gives a NullPointerException at Hibernate 6.0.0.Alpha4:
Test file:
{code:title=Hbug.java|borderStyle=solid}
package com.example;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import javax.persistence.spi.PersistenceProvider;
import org.hibernate.SessionFactory;
import org.hibernate.jpa.HibernatePersistenceProvider;
/**
* @author Victor Williams Stafusa da Silva
*/
public class Hbug {
public static void main(String[] args) throws Exception {
Map<String, String> props = new HashMap<>();
props.put("javax.persistence.jdbc.user", "sa");
props.put("javax.persistence.jdbc.password", "");
props.put("javax.persistence.jdbc.url", "jdbc:hsqldb:mem:test1");
props.put("hibernate.hbm2ddl.import_files_sql_extractor", "org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor");
props.put("javax.persistence.schema-generation.database.action", "drop-and-create");
PersistenceProvider pp = new HibernatePersistenceProvider();
var spui = new SimplePersistenceUnitInfo(
Optional.empty(),
HibernatePersistenceProvider.class,
"test-1",
Set.of(Fruit.class),
props);
var emf = pp.createContainerEntityManagerFactory(spui, props);
if (!(emf instanceof SessionFactory)) throw new Exception("Bad EMF");
}
}
{code}
Utilitary class used by the above one:
{code:title=SimplePersistenceUnitInfo.java|borderStyle=solid}
package com.example;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.stream.Collectors;
import javax.persistence.SharedCacheMode;
import javax.persistence.ValidationMode;
import javax.persistence.spi.ClassTransformer;
import javax.persistence.spi.PersistenceProvider;
import javax.persistence.spi.PersistenceUnitInfo;
import javax.persistence.spi.PersistenceUnitTransactionType;
import javax.sql.DataSource;
/**
* @author Victor Williams Stafusa da Silva
*/
public final class SimplePersistenceUnitInfo implements PersistenceUnitInfo {
private final Optional<URL> url;
private final Class<? extends PersistenceProvider> providerClass;
private final String persistenceUnitName;
private final List<String> classes;
private final Map<String, String> properties;
public SimplePersistenceUnitInfo(
/*@NonNull*/ Optional<URL> url,
/*@NonNull*/ Class<? extends PersistenceProvider> providerClass,
/*@NonNull*/ String persistenceUnitName,
/*@NonNull*/ Collection<Class<?>> classes,
/*@NonNull*/ Map<String, String> properties)
{
this.url = url;
this.providerClass = providerClass;
this.persistenceUnitName = persistenceUnitName;
this.classes = classes.stream().map(Class::getName).collect(Collectors.toList());
this.properties = new HashMap<>();
this.properties.putAll(properties);
}
@Override
public String getPersistenceUnitName() {
return persistenceUnitName;
}
@Override
public String getPersistenceProviderClassName() {
return providerClass.getName();
}
@Override
public PersistenceUnitTransactionType getTransactionType() {
return PersistenceUnitTransactionType.RESOURCE_LOCAL;
}
@Override
//@Nullable
public DataSource getJtaDataSource() {
return null;
}
@Override
//@Nullable
public DataSource getNonJtaDataSource() {
return null;
}
@Override
public List<String> getMappingFileNames() {
return Collections.emptyList();
}
@Override
public List<URL> getJarFileUrls() {
try {
return Collections.list(this.getClass().getClassLoader().getResources(""));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
//@Nullable
@Override
public URL getPersistenceUnitRootUrl() {
return url.orElse(null);
}
@Override
public List<String> getManagedClassNames() {
return Collections.unmodifiableList(classes);
}
@Override
public boolean excludeUnlistedClasses() {
return false;
}
@Override
public SharedCacheMode getSharedCacheMode() {
return SharedCacheMode.UNSPECIFIED;
}
@Override
public ValidationMode getValidationMode() {
return ValidationMode.AUTO;
}
@Override
public Properties getProperties() {
Properties p = new Properties();
p.putAll(properties);
return p;
}
@Override
public String getPersistenceXMLSchemaVersion() {
return "2.2";
}
@Override
//@Nullable
public ClassLoader getClassLoader() {
return Thread.currentThread().getContextClassLoader();
}
@Override
public void addTransformer(ClassTransformer transformer) {
}
@Override
//@Nullable
public ClassLoader getNewTempClassLoader() {
return null;
}
}
{code}
Sample entity class:
{code:title=Fruit.java|borderStyle=solid}
package com.example;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
/**
* @author Victor Williams Stafusa da Silva
*/
@Entity
@Table(name = "fruits")
public class Fruit implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String name;
private String color;
public Fruit() {}
public Fruit(String name, String color) {
this.name = name;
this.color = color;
}
public String getName() {
return name;
}
public String getColor() {
return color;
}
}
{code}
Gradle script to build that:
{code:title=build.gradle|borderStyle=solid}
apply plugin: 'java'
apply plugin: 'application'
group = 'com.example'
mainClassName = 'com.example.Hbug'
repositories {
jcenter()
}
dependencies {
implementation 'org.hsqldb:hsqldb:2.5.0'
//implementation 'org.hibernate:hibernate-core:5.4.13.Final'
implementation 'org.hibernate.orm:hibernate-core:6.0.0.Alpha4'
}
{code}
Run the code above and a NullPointerException will be throw (with Hibernate 6.0.0.Alpha4). However, if the gradle file is changed to use Hibernate 5.4.13 (uncomment that line and comment the one for 6.0.0.Alpha4), then the code works as expected.
Here is the output, including the stack trace:
{code:title=output|borderStyle=solid}
Apr 07, 2020 7:19:53 AM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
INFO: HHH000204: Processing PersistenceUnitInfo [name: test-1]
Apr 07, 2020 7:19:54 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {6.0.0.Alpha4}
Apr 07, 2020 7:19:54 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
Exception in thread "main" java.lang.NullPointerException
at org.hibernate.boot.archive.scan.spi.ClassFileArchiveEntryHandler.toClassDescriptor(ClassFileArchiveEntryHandler.java:84)
at org.hibernate.boot.archive.scan.spi.ClassFileArchiveEntryHandler.toClassDescriptor(ClassFileArchiveEntryHandler.java:67)
at org.hibernate.boot.archive.scan.spi.ClassFileArchiveEntryHandler.handleEntry(ClassFileArchiveEntryHandler.java:53)
at org.hibernate.boot.archive.internal.JarFileBasedArchiveDescriptor.visitArchive(JarFileBasedArchiveDescriptor.java:147)
at org.hibernate.boot.archive.internal.JarProtocolArchiveDescriptor.visitArchive(JarProtocolArchiveDescriptor.java:59)
at org.hibernate.boot.archive.scan.spi.AbstractScannerImpl.scan(AbstractScannerImpl.java:40)
at org.hibernate.boot.model.process.internal.ScanningCoordinator.coordinateScan(ScanningCoordinator.java:74)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.prepare(MetadataBuildingProcess.java:97)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:243)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:169)
at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:32)
at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:89)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:166)
at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:141)
at com.example.Hbug.main(Hbug.java:31)
{code}
P.S.: I'm running this using
was:
This code works fine in Hibernate 5.4.13.Final, but gives a NullPointerException at Hibernate 6.0.0.Alpha4:
Test file:
{code:title=Hbug.java|borderStyle=solid}
package com.example;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import javax.persistence.spi.PersistenceProvider;
import org.hibernate.SessionFactory;
import org.hibernate.jpa.HibernatePersistenceProvider;
/**
* @author Victor Williams Stafusa da Silva
*/
public class Hbug {
public static void main(String[] args) throws Exception {
Map<String, String> props = new HashMap<>();
props.put("javax.persistence.jdbc.user", "sa");
props.put("javax.persistence.jdbc.password", "");
props.put("javax.persistence.jdbc.url", "jdbc:hsqldb:mem:test1");
props.put("hibernate.hbm2ddl.import_files_sql_extractor", "org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor");
props.put("javax.persistence.schema-generation.database.action", "drop-and-create");
PersistenceProvider pp = new HibernatePersistenceProvider();
var spui = new SimplePersistenceUnitInfo(
Optional.empty(),
HibernatePersistenceProvider.class,
"test-1",
Set.of(Fruit.class),
props);
var emf = pp.createContainerEntityManagerFactory(spui, props);
if (!(emf instanceof SessionFactory)) throw new Exception("Bad EMF");
}
}
{code}
Utilitary class used by the above one:
{code:title=SimplePersistenceUnitInfo.java|borderStyle=solid}
package com.example;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.stream.Collectors;
import javax.persistence.SharedCacheMode;
import javax.persistence.ValidationMode;
import javax.persistence.spi.ClassTransformer;
import javax.persistence.spi.PersistenceProvider;
import javax.persistence.spi.PersistenceUnitInfo;
import javax.persistence.spi.PersistenceUnitTransactionType;
import javax.sql.DataSource;
/**
* @author Victor Williams Stafusa da Silva
*/
public final class SimplePersistenceUnitInfo implements PersistenceUnitInfo {
private final Optional<URL> url;
private final Class<? extends PersistenceProvider> providerClass;
private final String persistenceUnitName;
private final List<String> classes;
private final Map<String, String> properties;
public SimplePersistenceUnitInfo(
/*@NonNull*/ Optional<URL> url,
/*@NonNull*/ Class<? extends PersistenceProvider> providerClass,
/*@NonNull*/ String persistenceUnitName,
/*@NonNull*/ Collection<Class<?>> classes,
/*@NonNull*/ Map<String, String> properties)
{
this.url = url;
this.providerClass = providerClass;
this.persistenceUnitName = persistenceUnitName;
this.classes = classes.stream().map(Class::getName).collect(Collectors.toList());
this.properties = new HashMap<>();
this.properties.putAll(properties);
}
@Override
public String getPersistenceUnitName() {
return persistenceUnitName;
}
@Override
public String getPersistenceProviderClassName() {
return providerClass.getName();
}
@Override
public PersistenceUnitTransactionType getTransactionType() {
return PersistenceUnitTransactionType.RESOURCE_LOCAL;
}
@Override
//@Nullable
public DataSource getJtaDataSource() {
return null;
}
@Override
//@Nullable
public DataSource getNonJtaDataSource() {
return null;
}
@Override
public List<String> getMappingFileNames() {
return Collections.emptyList();
}
@Override
public List<URL> getJarFileUrls() {
try {
return Collections.list(this.getClass().getClassLoader().getResources(""));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
//@Nullable
@Override
public URL getPersistenceUnitRootUrl() {
return url.orElse(null);
}
@Override
public List<String> getManagedClassNames() {
return Collections.unmodifiableList(classes);
}
@Override
public boolean excludeUnlistedClasses() {
return false;
}
@Override
public SharedCacheMode getSharedCacheMode() {
return SharedCacheMode.UNSPECIFIED;
}
@Override
public ValidationMode getValidationMode() {
return ValidationMode.AUTO;
}
@Override
public Properties getProperties() {
Properties p = new Properties();
p.putAll(properties);
return p;
}
@Override
public String getPersistenceXMLSchemaVersion() {
return "2.2";
}
@Override
//@Nullable
public ClassLoader getClassLoader() {
return Thread.currentThread().getContextClassLoader();
}
@Override
public void addTransformer(ClassTransformer transformer) {
}
@Override
//@Nullable
public ClassLoader getNewTempClassLoader() {
return null;
}
}
{code}
Sample entity class:
{code:title=Fruit.java|borderStyle=solid}
package com.example;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
/**
* @author Victor Williams Stafusa da Silva
*/
@Entity
@Table(name = "fruits")
public class Fruit implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String name;
private String color;
public Fruit() {}
public Fruit(String name, String color) {
this.name = name;
this.color = color;
}
public String getName() {
return name;
}
public String getColor() {
return color;
}
}
{code}
Gradle script to build that:
{code:title=build.gradle|borderStyle=solid}
apply plugin: 'java'
apply plugin: 'application'
group = 'com.example'
mainClassName = 'com.example.Hbug'
repositories {
jcenter()
}
dependencies {
implementation 'org.hsqldb:hsqldb:2.5.0'
//implementation 'org.hibernate:hibernate-core:5.4.13.Final'
implementation 'org.hibernate.orm:hibernate-core:6.0.0.Alpha4'
}
{code}
> NullPointerException at org.hibernate.boot.archive.scan.spi.ClassFileArchiveEntryHandler.toClassDescriptor - Hibernate 6.0.0.Alpha4
> -----------------------------------------------------------------------------------------------------------------------------------
>
> Key: HIBERNATE-174
> URL: https://issues.redhat.com/browse/HIBERNATE-174
> Project: Hibernate Integration
> Issue Type: Bug
> Reporter: Victor Williams Stafusa da Silva
> Assignee: Steve Ebersole
> Priority: Critical
>
> This code works fine in Hibernate 5.4.13.Final, but gives a NullPointerException at Hibernate 6.0.0.Alpha4:
> Test file:
> {code:title=Hbug.java|borderStyle=solid}
> package com.example;
> import java.util.HashMap;
> import java.util.Map;
> import java.util.Optional;
> import java.util.Set;
> import javax.persistence.spi.PersistenceProvider;
> import org.hibernate.SessionFactory;
> import org.hibernate.jpa.HibernatePersistenceProvider;
> /**
> * @author Victor Williams Stafusa da Silva
> */
> public class Hbug {
> public static void main(String[] args) throws Exception {
> Map<String, String> props = new HashMap<>();
> props.put("javax.persistence.jdbc.user", "sa");
> props.put("javax.persistence.jdbc.password", "");
> props.put("javax.persistence.jdbc.url", "jdbc:hsqldb:mem:test1");
> props.put("hibernate.hbm2ddl.import_files_sql_extractor", "org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor");
> props.put("javax.persistence.schema-generation.database.action", "drop-and-create");
> PersistenceProvider pp = new HibernatePersistenceProvider();
> var spui = new SimplePersistenceUnitInfo(
> Optional.empty(),
> HibernatePersistenceProvider.class,
> "test-1",
> Set.of(Fruit.class),
> props);
> var emf = pp.createContainerEntityManagerFactory(spui, props);
> if (!(emf instanceof SessionFactory)) throw new Exception("Bad EMF");
> }
> }
> {code}
> Utilitary class used by the above one:
> {code:title=SimplePersistenceUnitInfo.java|borderStyle=solid}
> package com.example;
> import java.io.IOException;
> import java.io.UncheckedIOException;
> import java.net.URL;
> import java.util.Collection;
> import java.util.Collections;
> import java.util.HashMap;
> import java.util.List;
> import java.util.Map;
> import java.util.Optional;
> import java.util.Properties;
> import java.util.stream.Collectors;
> import javax.persistence.SharedCacheMode;
> import javax.persistence.ValidationMode;
> import javax.persistence.spi.ClassTransformer;
> import javax.persistence.spi.PersistenceProvider;
> import javax.persistence.spi.PersistenceUnitInfo;
> import javax.persistence.spi.PersistenceUnitTransactionType;
> import javax.sql.DataSource;
> /**
> * @author Victor Williams Stafusa da Silva
> */
> public final class SimplePersistenceUnitInfo implements PersistenceUnitInfo {
> private final Optional<URL> url;
> private final Class<? extends PersistenceProvider> providerClass;
> private final String persistenceUnitName;
> private final List<String> classes;
> private final Map<String, String> properties;
> public SimplePersistenceUnitInfo(
> /*@NonNull*/ Optional<URL> url,
> /*@NonNull*/ Class<? extends PersistenceProvider> providerClass,
> /*@NonNull*/ String persistenceUnitName,
> /*@NonNull*/ Collection<Class<?>> classes,
> /*@NonNull*/ Map<String, String> properties)
> {
> this.url = url;
> this.providerClass = providerClass;
> this.persistenceUnitName = persistenceUnitName;
> this.classes = classes.stream().map(Class::getName).collect(Collectors.toList());
> this.properties = new HashMap<>();
> this.properties.putAll(properties);
> }
> @Override
> public String getPersistenceUnitName() {
> return persistenceUnitName;
> }
> @Override
> public String getPersistenceProviderClassName() {
> return providerClass.getName();
> }
> @Override
> public PersistenceUnitTransactionType getTransactionType() {
> return PersistenceUnitTransactionType.RESOURCE_LOCAL;
> }
> @Override
> //@Nullable
> public DataSource getJtaDataSource() {
> return null;
> }
> @Override
> //@Nullable
> public DataSource getNonJtaDataSource() {
> return null;
> }
> @Override
> public List<String> getMappingFileNames() {
> return Collections.emptyList();
> }
> @Override
> public List<URL> getJarFileUrls() {
> try {
> return Collections.list(this.getClass().getClassLoader().getResources(""));
> } catch (IOException e) {
> throw new UncheckedIOException(e);
> }
> }
> //@Nullable
> @Override
> public URL getPersistenceUnitRootUrl() {
> return url.orElse(null);
> }
> @Override
> public List<String> getManagedClassNames() {
> return Collections.unmodifiableList(classes);
> }
> @Override
> public boolean excludeUnlistedClasses() {
> return false;
> }
> @Override
> public SharedCacheMode getSharedCacheMode() {
> return SharedCacheMode.UNSPECIFIED;
> }
> @Override
> public ValidationMode getValidationMode() {
> return ValidationMode.AUTO;
> }
> @Override
> public Properties getProperties() {
> Properties p = new Properties();
> p.putAll(properties);
> return p;
> }
> @Override
> public String getPersistenceXMLSchemaVersion() {
> return "2.2";
> }
> @Override
> //@Nullable
> public ClassLoader getClassLoader() {
> return Thread.currentThread().getContextClassLoader();
> }
> @Override
> public void addTransformer(ClassTransformer transformer) {
> }
> @Override
> //@Nullable
> public ClassLoader getNewTempClassLoader() {
> return null;
> }
> }
> {code}
> Sample entity class:
> {code:title=Fruit.java|borderStyle=solid}
> package com.example;
> import java.io.Serializable;
> import javax.persistence.Entity;
> import javax.persistence.GeneratedValue;
> import javax.persistence.GenerationType;
> import javax.persistence.Id;
> import javax.persistence.Table;
> /**
> * @author Victor Williams Stafusa da Silva
> */
> @Entity
> @Table(name = "fruits")
> public class Fruit implements Serializable {
> private static final long serialVersionUID = 1L;
> @Id
> @GeneratedValue(strategy = GenerationType.IDENTITY)
> private Integer id;
> private String name;
> private String color;
> public Fruit() {}
> public Fruit(String name, String color) {
> this.name = name;
> this.color = color;
> }
> public String getName() {
> return name;
> }
> public String getColor() {
> return color;
> }
> }
> {code}
> Gradle script to build that:
> {code:title=build.gradle|borderStyle=solid}
> apply plugin: 'java'
> apply plugin: 'application'
> group = 'com.example'
> mainClassName = 'com.example.Hbug'
> repositories {
> jcenter()
> }
> dependencies {
> implementation 'org.hsqldb:hsqldb:2.5.0'
> //implementation 'org.hibernate:hibernate-core:5.4.13.Final'
> implementation 'org.hibernate.orm:hibernate-core:6.0.0.Alpha4'
> }
> {code}
> Run the code above and a NullPointerException will be throw (with Hibernate 6.0.0.Alpha4). However, if the gradle file is changed to use Hibernate 5.4.13 (uncomment that line and comment the one for 6.0.0.Alpha4), then the code works as expected.
> Here is the output, including the stack trace:
> {code:title=output|borderStyle=solid}
> Apr 07, 2020 7:19:53 AM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
> INFO: HHH000204: Processing PersistenceUnitInfo [name: test-1]
> Apr 07, 2020 7:19:54 AM org.hibernate.Version logVersion
> INFO: HHH000412: Hibernate Core {6.0.0.Alpha4}
> Apr 07, 2020 7:19:54 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
> INFO: HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
> Exception in thread "main" java.lang.NullPointerException
> at org.hibernate.boot.archive.scan.spi.ClassFileArchiveEntryHandler.toClassDescriptor(ClassFileArchiveEntryHandler.java:84)
> at org.hibernate.boot.archive.scan.spi.ClassFileArchiveEntryHandler.toClassDescriptor(ClassFileArchiveEntryHandler.java:67)
> at org.hibernate.boot.archive.scan.spi.ClassFileArchiveEntryHandler.handleEntry(ClassFileArchiveEntryHandler.java:53)
> at org.hibernate.boot.archive.internal.JarFileBasedArchiveDescriptor.visitArchive(JarFileBasedArchiveDescriptor.java:147)
> at org.hibernate.boot.archive.internal.JarProtocolArchiveDescriptor.visitArchive(JarProtocolArchiveDescriptor.java:59)
> at org.hibernate.boot.archive.scan.spi.AbstractScannerImpl.scan(AbstractScannerImpl.java:40)
> at org.hibernate.boot.model.process.internal.ScanningCoordinator.coordinateScan(ScanningCoordinator.java:74)
> at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.prepare(MetadataBuildingProcess.java:97)
> at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:243)
> at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:169)
> at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:32)
> at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:89)
> at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:166)
> at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:141)
> at com.example.Hbug.main(Hbug.java:31)
> {code}
> P.S.: I'm running this using
--
This message was sent by Atlassian Jira
(v7.13.8#713008)
4 years, 6 months
[JBoss JIRA] (WFCORE-2516) Changes to the logging subsystem are not persisted to the logging.properties in offline CLI
by Bartosz Baranowski (Jira)
[ https://issues.redhat.com/browse/WFCORE-2516?page=com.atlassian.jira.plug... ]
Bartosz Baranowski edited comment on WFCORE-2516 at 4/7/20 6:15 AM:
--------------------------------------------------------------------
Most likely this should be handled as RFE?
was (Author: baranowb):
Most likely this should be treated as RFE?
> Changes to the logging subsystem are not persisted to the logging.properties in offline CLI
> -------------------------------------------------------------------------------------------
>
> Key: WFCORE-2516
> URL: https://issues.redhat.com/browse/WFCORE-2516
> Project: WildFly Core
> Issue Type: Bug
> Components: Logging
> Reporter: James Perkins
> Assignee: James Perkins
> Priority: Major
>
> When using {{embed-server}} within offline CLI changes to the logging subsystem are not persisted to the {{logging.properties}} file.
> Do note that before we fix this we may want to consider a fix for WFCORE-157. The issue being that offline CLI is likely used to provision a server and that server may be configured in a different location. Since the {{jboss.server.log.dir}} or other {{relative-to}} property will be resolved and written as a fully-qualified path this could be an issue.
--
This message was sent by Atlassian Jira
(v7.13.8#713008)
4 years, 6 months
[JBoss JIRA] (WFCORE-2516) Changes to the logging subsystem are not persisted to the logging.properties in offline CLI
by Bartosz Baranowski (Jira)
[ https://issues.redhat.com/browse/WFCORE-2516?page=com.atlassian.jira.plug... ]
Bartosz Baranowski commented on WFCORE-2516:
--------------------------------------------
Most likely this should be treated as RFE?
> Changes to the logging subsystem are not persisted to the logging.properties in offline CLI
> -------------------------------------------------------------------------------------------
>
> Key: WFCORE-2516
> URL: https://issues.redhat.com/browse/WFCORE-2516
> Project: WildFly Core
> Issue Type: Bug
> Components: Logging
> Reporter: James Perkins
> Assignee: James Perkins
> Priority: Major
>
> When using {{embed-server}} within offline CLI changes to the logging subsystem are not persisted to the {{logging.properties}} file.
> Do note that before we fix this we may want to consider a fix for WFCORE-157. The issue being that offline CLI is likely used to provision a server and that server may be configured in a different location. Since the {{jboss.server.log.dir}} or other {{relative-to}} property will be resolved and written as a fully-qualified path this could be an issue.
--
This message was sent by Atlassian Jira
(v7.13.8#713008)
4 years, 6 months
[JBoss JIRA] (WFLY-13341) Substitution of environment / system properties for microprofile-opentracing-smallrye extension
by Yeray Borges Santana (Jira)
Yeray Borges Santana created WFLY-13341:
-------------------------------------------
Summary: Substitution of environment / system properties for microprofile-opentracing-smallrye extension
Key: WFLY-13341
URL: https://issues.redhat.com/browse/WFLY-13341
Project: WildFly
Issue Type: Feature Request
Components: MP OpenTracing
Affects Versions: 19.0.0.Final
Reporter: Yeray Borges Santana
Assignee: Emmanuel Hugonnet
I would like to able to configure the microprofile-opentracing-smallrye extension in wildfly 19 with substituted variables (environment or system).
When I try this it seems the values are not resolved, for example
{code:xml}
<subsystem xmlns="urn:wildfly:microprofile-opentracing-smallrye:2.0" default-tracer="jaeger">
<jaeger-tracer name="jaeger">
<tags>
<property name="env" value="${env.ENV}"/>
<property name="user" value="joe"/>
</tags>
<sampler-configuration sampler-type="ratelimiting" sampler-param="1.0"/>
<sender-configuration sender-endpoint="http://${JAEGER_AGENT_HOST}:14268/api/traces"/>
</jaeger-tracer>
</subsystem>
{code}
results in:
{noformat}
2020-03-29 15:17:49,448 ERROR [jaeger.RemoteReporter-QueueProcessor] [] [] [] [] [] (io.jaegertracing.internal.reporters
.RemoteReporter) QueueProcessor error:: java.lang.RuntimeException: java.net.URISyntaxException: Illegal character in au
thority at index 7: http://${jaeger_agent_host}:14268/
at com.squareup.okhttp3//okhttp3.HttpUrl.uri(HttpUrl.java:385)
at com.squareup.okhttp3//okhttp3.internal.connection.RouteSelector.resetNextProxy(RouteSelector.java:129)
at com.squareup.okhttp3//okhttp3.internal.connection.RouteSelector.<init>(RouteSelector.java:63)
at com.squareup.okhttp3//okhttp3.internal.connection.StreamAllocation.<init>(StreamAllocation.java:101)
{noformat}
--
This message was sent by Atlassian Jira
(v7.13.8#713008)
4 years, 6 months
[JBoss JIRA] (HIBERNATE-174) NullPointerException at org.hibernate.boot.archive.scan.spi.ClassFileArchiveEntryHandler.toClassDescriptor - Hibernate 6.0.0.Alpha4
by Victor Williams Stafusa da Silva (Jira)
[ https://issues.redhat.com/browse/HIBERNATE-174?page=com.atlassian.jira.pl... ]
Victor Williams Stafusa da Silva updated HIBERNATE-174:
-------------------------------------------------------
Description:
This code works fine in Hibernate 5.4.13.Final, but gives a NullPointerException at Hibernate 6.0.0.Alpha4:
Test file:
{code:title=Hbug.java|borderStyle=solid}
package com.example;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import javax.persistence.spi.PersistenceProvider;
import org.hibernate.SessionFactory;
import org.hibernate.jpa.HibernatePersistenceProvider;
/**
* @author Victor Williams Stafusa da Silva
*/
public class Hbug {
public static void main(String[] args) throws Exception {
Map<String, String> props = new HashMap<>();
props.put("javax.persistence.jdbc.user", "sa");
props.put("javax.persistence.jdbc.password", "");
props.put("javax.persistence.jdbc.url", "jdbc:hsqldb:mem:test1");
props.put("hibernate.hbm2ddl.import_files_sql_extractor", "org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor");
props.put("javax.persistence.schema-generation.database.action", "drop-and-create");
PersistenceProvider pp = new HibernatePersistenceProvider();
var spui = new SimplePersistenceUnitInfo(
Optional.empty(),
HibernatePersistenceProvider.class,
"test-1",
Set.of(Fruit.class),
props);
var emf = pp.createContainerEntityManagerFactory(spui, props);
if (!(emf instanceof SessionFactory)) throw new Exception("Bad EMF");
}
}
{code}
Utilitary class used by the above one:
{code:title=SimplePersistenceUnitInfo.java|borderStyle=solid}
package com.example;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.stream.Collectors;
import javax.persistence.SharedCacheMode;
import javax.persistence.ValidationMode;
import javax.persistence.spi.ClassTransformer;
import javax.persistence.spi.PersistenceProvider;
import javax.persistence.spi.PersistenceUnitInfo;
import javax.persistence.spi.PersistenceUnitTransactionType;
import javax.sql.DataSource;
/**
* @author Victor Williams Stafusa da Silva
*/
public final class SimplePersistenceUnitInfo implements PersistenceUnitInfo {
private final Optional<URL> url;
private final Class<? extends PersistenceProvider> providerClass;
private final String persistenceUnitName;
private final List<String> classes;
private final Map<String, String> properties;
public SimplePersistenceUnitInfo(
/*@NonNull*/ Optional<URL> url,
/*@NonNull*/ Class<? extends PersistenceProvider> providerClass,
/*@NonNull*/ String persistenceUnitName,
/*@NonNull*/ Collection<Class<?>> classes,
/*@NonNull*/ Map<String, String> properties)
{
this.url = url;
this.providerClass = providerClass;
this.persistenceUnitName = persistenceUnitName;
this.classes = classes.stream().map(Class::getName).collect(Collectors.toList());
this.properties = new HashMap<>();
this.properties.putAll(properties);
}
@Override
public String getPersistenceUnitName() {
return persistenceUnitName;
}
@Override
public String getPersistenceProviderClassName() {
return providerClass.getName();
}
@Override
public PersistenceUnitTransactionType getTransactionType() {
return PersistenceUnitTransactionType.RESOURCE_LOCAL;
}
@Override
//@Nullable
public DataSource getJtaDataSource() {
return null;
}
@Override
//@Nullable
public DataSource getNonJtaDataSource() {
return null;
}
@Override
public List<String> getMappingFileNames() {
return Collections.emptyList();
}
@Override
public List<URL> getJarFileUrls() {
try {
return Collections.list(this.getClass().getClassLoader().getResources(""));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
//@Nullable
@Override
public URL getPersistenceUnitRootUrl() {
return url.orElse(null);
}
@Override
public List<String> getManagedClassNames() {
return Collections.unmodifiableList(classes);
}
@Override
public boolean excludeUnlistedClasses() {
return false;
}
@Override
public SharedCacheMode getSharedCacheMode() {
return SharedCacheMode.UNSPECIFIED;
}
@Override
public ValidationMode getValidationMode() {
return ValidationMode.AUTO;
}
@Override
public Properties getProperties() {
Properties p = new Properties();
p.putAll(properties);
return p;
}
@Override
public String getPersistenceXMLSchemaVersion() {
return "2.2";
}
@Override
//@Nullable
public ClassLoader getClassLoader() {
return Thread.currentThread().getContextClassLoader();
}
@Override
public void addTransformer(ClassTransformer transformer) {
}
@Override
//@Nullable
public ClassLoader getNewTempClassLoader() {
return null;
}
}
{code}
Sample entity class:
{code:title=Fruit.java|borderStyle=solid}
package com.example;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
/**
* @author Victor Williams Stafusa da Silva
*/
@Entity
@Table(name = "fruits")
public class Fruit implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String name;
private String color;
public Fruit() {}
public Fruit(String name, String color) {
this.name = name;
this.color = color;
}
public String getName() {
return name;
}
public String getColor() {
return color;
}
}
{code}
Gradle script to build that:
{code:title=build.gradle|borderStyle=solid}
apply plugin: 'java'
apply plugin: 'application'
group = 'com.example'
mainClassName = 'com.example.Hbug'
repositories {
jcenter()
}
dependencies {
implementation 'org.hsqldb:hsqldb:2.5.0'
//implementation 'org.hibernate:hibernate-core:5.4.13.Final'
implementation 'org.hibernate.orm:hibernate-core:6.0.0.Alpha4'
}
{code}
was:
This code works fine in Hibernate 5.4.13.Final, but gives a NullPointerException at Hibernate 6.0.0.Alpha4:
Test file:
{code:title=Hbug.java|borderStyle=solid}
package com.example;
import java.net.URL;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
import org.apache.openjpa.persistence.PersistenceProviderImpl;
import org.eclipse.persistence.jpa.JpaEntityManagerFactory;
import org.hibernate.SessionFactory;
import org.hibernate.jpa.HibernatePersistenceProvider;
/**
* @author Victor Williams Stafusa da Silva
*/
public class Hbug {
public static void main(String[] args) {
List.<TestSomething>of(Hbug::testHibernate, Hbug::testEclipselink, Hbug::testOpenJpa)
.forEach(TestSomething::outer);
}
private interface TestSomething {
public void inner() throws Exception;
public default void outer() {
try {
inner();
System.out.println("Ok");
} catch (Exception e) {
e.printStackTrace();
}
}
}
private static void testHibernate() throws Exception {
Map<String, String> props = new HashMap<>();
props.put("javax.persistence.jdbc.user", "sa");
props.put("javax.persistence.jdbc.password", "");
props.put("javax.persistence.jdbc.url", "jdbc:hsqldb:mem:test1");
props.put("hibernate.hbm2ddl.import_files_sql_extractor", "org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor");
props.put("javax.persistence.schema-generation.database.action", "drop-and-create");
Set<Class<?>> entities = new HashSet<>();
entities.add(Fruit.class);
String pu = "test-1";
javax.persistence.spi.PersistenceProvider pp = new HibernatePersistenceProvider();
var spui = new SimplePersistenceUnitInfo(Optional.empty(), HibernatePersistenceProvider.class, pu, entities, props);
var emf = pp.createContainerEntityManagerFactory(spui, props);
if (!(emf instanceof SessionFactory)) throw new Exception("Bad EMF");
}
private static void testEclipselink() throws Exception {
Map<String, String> props = new HashMap<>();
props.put("javax.persistence.jdbc.user", "sa");
props.put("javax.persistence.jdbc.password", "");
props.put("javax.persistence.jdbc.url", "jdbc:hsqldb:mem:test1");
props.put("javax.persistence.schema-generation.database.action", "drop-and-create");
Set<Class<?>> entities = new HashSet<>();
entities.add(Fruit.class);
String pu = "test-1";
javax.persistence.spi.PersistenceProvider pp = new org.eclipse.persistence.jpa.PersistenceProvider();
var spui = new SimplePersistenceUnitInfo(Optional.of(new URL("http://0.0.0.0/")), pp.getClass(), pu, entities, props);
var emf = pp.createContainerEntityManagerFactory(spui, props);
if (!(emf instanceof JpaEntityManagerFactory)) throw new Exception("Bad EMF");
}
private static void testOpenJpa() throws Exception {
Map<String, String> props = new HashMap<>();
props.put("javax.persistence.jdbc.user", "sa");
props.put("javax.persistence.jdbc.password", "");
props.put("javax.persistence.jdbc.url", "jdbc:hsqldb:mem:test1");
props.put("javax.persistence.jdbc.driver", "org.hsqldb.jdbc.JDBCDriver");
props.put("javax.persistence.schema-generation.database.action", "drop-and-create");
props.put("openjpa.DynamicEnhancementAgent", "true");
props.put("openjpa.RuntimeUnenhancedClasses", "supported");
Set<Class<?>> entities = new HashSet<>();
entities.add(Fruit.class);
String pu = "test-1";
javax.persistence.spi.PersistenceProvider pp = new PersistenceProviderImpl();
var spui = new SimplePersistenceUnitInfo(Optional.empty(), pp.getClass(), pu, entities, props);
var emf = pp.createContainerEntityManagerFactory(spui, props);
if (!(emf instanceof OpenJPAEntityManagerFactory)) throw new Exception("Bad EMF");
}
}
{code}
Utilitary class used by the above one:
{code:title=SimplePersistenceUnitInfo.java|borderStyle=solid}
package com.example;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.stream.Collectors;
import javax.persistence.SharedCacheMode;
import javax.persistence.ValidationMode;
import javax.persistence.spi.ClassTransformer;
import javax.persistence.spi.PersistenceProvider;
import javax.persistence.spi.PersistenceUnitInfo;
import javax.persistence.spi.PersistenceUnitTransactionType;
import javax.sql.DataSource;
/**
* @author Victor Williams Stafusa da Silva
*/
public final class SimplePersistenceUnitInfo implements PersistenceUnitInfo {
private final Optional<URL> url;
private final Class<? extends PersistenceProvider> providerClass;
private final String persistenceUnitName;
private final List<String> classes;
private final Map<String, String> properties;
public SimplePersistenceUnitInfo(
/*@NonNull*/ Optional<URL> url,
/*@NonNull*/ Class<? extends PersistenceProvider> providerClass,
/*@NonNull*/ String persistenceUnitName,
/*@NonNull*/ Collection<Class<?>> classes,
/*@NonNull*/ Map<String, String> properties)
{
this.url = url;
this.providerClass = providerClass;
this.persistenceUnitName = persistenceUnitName;
this.classes = classes.stream().map(Class::getName).collect(Collectors.toList());
this.properties = new HashMap<>();
this.properties.putAll(properties);
}
@Override
public String getPersistenceUnitName() {
return persistenceUnitName;
}
@Override
public String getPersistenceProviderClassName() {
return providerClass.getName();
}
@Override
public PersistenceUnitTransactionType getTransactionType() {
return PersistenceUnitTransactionType.RESOURCE_LOCAL;
}
@Override
//@Nullable
public DataSource getJtaDataSource() {
return null;
}
@Override
//@Nullable
public DataSource getNonJtaDataSource() {
return null;
}
@Override
public List<String> getMappingFileNames() {
return Collections.emptyList();
}
@Override
public List<URL> getJarFileUrls() {
try {
return Collections.list(this.getClass().getClassLoader().getResources(""));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
//@Nullable
@Override
public URL getPersistenceUnitRootUrl() {
return url.orElse(null);
}
@Override
public List<String> getManagedClassNames() {
return Collections.unmodifiableList(classes);
}
@Override
public boolean excludeUnlistedClasses() {
return false;
}
@Override
public SharedCacheMode getSharedCacheMode() {
return SharedCacheMode.UNSPECIFIED;
}
@Override
public ValidationMode getValidationMode() {
return ValidationMode.AUTO;
}
@Override
public Properties getProperties() {
Properties p = new Properties();
p.putAll(properties);
return p;
}
@Override
public String getPersistenceXMLSchemaVersion() {
return "2.2";
}
@Override
//@Nullable
public ClassLoader getClassLoader() {
return Thread.currentThread().getContextClassLoader();
}
@Override
public void addTransformer(ClassTransformer transformer) {
}
@Override
//@Nullable
public ClassLoader getNewTempClassLoader() {
return null;
}
}
{code}
Sample entity class:
{code:title=Fruit.java|borderStyle=solid}
package com.example;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
/**
* @author Victor Williams Stafusa da Silva
*/
@Entity
@Table(name = "fruits")
public class Fruit implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String name;
private String color;
public Fruit() {}
public Fruit(String name, String color) {
this.name = name;
this.color = color;
}
public String getName() {
return name;
}
public String getColor() {
return color;
}
}
{code}
Gradle script to build that:
{code:title=build.gradle|borderStyle=solid}
apply plugin: 'java'
apply plugin: 'application'
group = 'com.example'
mainClassName = 'com.example.Hbug'
repositories {
jcenter()
}
dependencies {
implementation 'org.hsqldb:hsqldb:2.5.0'
//implementation 'org.hibernate:hibernate-core:5.4.13.Final'
implementation 'org.hibernate.orm:hibernate-core:6.0.0.Alpha4'
}
{code}
> NullPointerException at org.hibernate.boot.archive.scan.spi.ClassFileArchiveEntryHandler.toClassDescriptor - Hibernate 6.0.0.Alpha4
> -----------------------------------------------------------------------------------------------------------------------------------
>
> Key: HIBERNATE-174
> URL: https://issues.redhat.com/browse/HIBERNATE-174
> Project: Hibernate Integration
> Issue Type: Bug
> Reporter: Victor Williams Stafusa da Silva
> Assignee: Steve Ebersole
> Priority: Critical
>
> This code works fine in Hibernate 5.4.13.Final, but gives a NullPointerException at Hibernate 6.0.0.Alpha4:
> Test file:
> {code:title=Hbug.java|borderStyle=solid}
> package com.example;
> import java.util.HashMap;
> import java.util.Map;
> import java.util.Optional;
> import java.util.Set;
> import javax.persistence.spi.PersistenceProvider;
> import org.hibernate.SessionFactory;
> import org.hibernate.jpa.HibernatePersistenceProvider;
> /**
> * @author Victor Williams Stafusa da Silva
> */
> public class Hbug {
> public static void main(String[] args) throws Exception {
> Map<String, String> props = new HashMap<>();
> props.put("javax.persistence.jdbc.user", "sa");
> props.put("javax.persistence.jdbc.password", "");
> props.put("javax.persistence.jdbc.url", "jdbc:hsqldb:mem:test1");
> props.put("hibernate.hbm2ddl.import_files_sql_extractor", "org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor");
> props.put("javax.persistence.schema-generation.database.action", "drop-and-create");
> PersistenceProvider pp = new HibernatePersistenceProvider();
> var spui = new SimplePersistenceUnitInfo(
> Optional.empty(),
> HibernatePersistenceProvider.class,
> "test-1",
> Set.of(Fruit.class),
> props);
> var emf = pp.createContainerEntityManagerFactory(spui, props);
> if (!(emf instanceof SessionFactory)) throw new Exception("Bad EMF");
> }
> }
> {code}
> Utilitary class used by the above one:
> {code:title=SimplePersistenceUnitInfo.java|borderStyle=solid}
> package com.example;
> import java.io.IOException;
> import java.io.UncheckedIOException;
> import java.net.URL;
> import java.util.Collection;
> import java.util.Collections;
> import java.util.HashMap;
> import java.util.List;
> import java.util.Map;
> import java.util.Optional;
> import java.util.Properties;
> import java.util.stream.Collectors;
> import javax.persistence.SharedCacheMode;
> import javax.persistence.ValidationMode;
> import javax.persistence.spi.ClassTransformer;
> import javax.persistence.spi.PersistenceProvider;
> import javax.persistence.spi.PersistenceUnitInfo;
> import javax.persistence.spi.PersistenceUnitTransactionType;
> import javax.sql.DataSource;
> /**
> * @author Victor Williams Stafusa da Silva
> */
> public final class SimplePersistenceUnitInfo implements PersistenceUnitInfo {
> private final Optional<URL> url;
> private final Class<? extends PersistenceProvider> providerClass;
> private final String persistenceUnitName;
> private final List<String> classes;
> private final Map<String, String> properties;
> public SimplePersistenceUnitInfo(
> /*@NonNull*/ Optional<URL> url,
> /*@NonNull*/ Class<? extends PersistenceProvider> providerClass,
> /*@NonNull*/ String persistenceUnitName,
> /*@NonNull*/ Collection<Class<?>> classes,
> /*@NonNull*/ Map<String, String> properties)
> {
> this.url = url;
> this.providerClass = providerClass;
> this.persistenceUnitName = persistenceUnitName;
> this.classes = classes.stream().map(Class::getName).collect(Collectors.toList());
> this.properties = new HashMap<>();
> this.properties.putAll(properties);
> }
> @Override
> public String getPersistenceUnitName() {
> return persistenceUnitName;
> }
> @Override
> public String getPersistenceProviderClassName() {
> return providerClass.getName();
> }
> @Override
> public PersistenceUnitTransactionType getTransactionType() {
> return PersistenceUnitTransactionType.RESOURCE_LOCAL;
> }
> @Override
> //@Nullable
> public DataSource getJtaDataSource() {
> return null;
> }
> @Override
> //@Nullable
> public DataSource getNonJtaDataSource() {
> return null;
> }
> @Override
> public List<String> getMappingFileNames() {
> return Collections.emptyList();
> }
> @Override
> public List<URL> getJarFileUrls() {
> try {
> return Collections.list(this.getClass().getClassLoader().getResources(""));
> } catch (IOException e) {
> throw new UncheckedIOException(e);
> }
> }
> //@Nullable
> @Override
> public URL getPersistenceUnitRootUrl() {
> return url.orElse(null);
> }
> @Override
> public List<String> getManagedClassNames() {
> return Collections.unmodifiableList(classes);
> }
> @Override
> public boolean excludeUnlistedClasses() {
> return false;
> }
> @Override
> public SharedCacheMode getSharedCacheMode() {
> return SharedCacheMode.UNSPECIFIED;
> }
> @Override
> public ValidationMode getValidationMode() {
> return ValidationMode.AUTO;
> }
> @Override
> public Properties getProperties() {
> Properties p = new Properties();
> p.putAll(properties);
> return p;
> }
> @Override
> public String getPersistenceXMLSchemaVersion() {
> return "2.2";
> }
> @Override
> //@Nullable
> public ClassLoader getClassLoader() {
> return Thread.currentThread().getContextClassLoader();
> }
> @Override
> public void addTransformer(ClassTransformer transformer) {
> }
> @Override
> //@Nullable
> public ClassLoader getNewTempClassLoader() {
> return null;
> }
> }
> {code}
> Sample entity class:
> {code:title=Fruit.java|borderStyle=solid}
> package com.example;
> import java.io.Serializable;
> import javax.persistence.Entity;
> import javax.persistence.GeneratedValue;
> import javax.persistence.GenerationType;
> import javax.persistence.Id;
> import javax.persistence.Table;
> /**
> * @author Victor Williams Stafusa da Silva
> */
> @Entity
> @Table(name = "fruits")
> public class Fruit implements Serializable {
> private static final long serialVersionUID = 1L;
> @Id
> @GeneratedValue(strategy = GenerationType.IDENTITY)
> private Integer id;
> private String name;
> private String color;
> public Fruit() {}
> public Fruit(String name, String color) {
> this.name = name;
> this.color = color;
> }
> public String getName() {
> return name;
> }
> public String getColor() {
> return color;
> }
> }
> {code}
> Gradle script to build that:
> {code:title=build.gradle|borderStyle=solid}
> apply plugin: 'java'
> apply plugin: 'application'
> group = 'com.example'
> mainClassName = 'com.example.Hbug'
> repositories {
> jcenter()
> }
> dependencies {
> implementation 'org.hsqldb:hsqldb:2.5.0'
> //implementation 'org.hibernate:hibernate-core:5.4.13.Final'
> implementation 'org.hibernate.orm:hibernate-core:6.0.0.Alpha4'
> }
> {code}
--
This message was sent by Atlassian Jira
(v7.13.8#713008)
4 years, 6 months