use of jakarta.persistence.Entity in project hibernate-orm by hibernate.
the class JPAXMLOverriddenAnnotationReader method getEntity.
private Entity getEntity(ManagedType element, XMLContext.Default defaults) {
if (element == null) {
return defaults.canUseJavaAnnotations() ? getPhysicalAnnotation(Entity.class) : null;
} else {
if (element instanceof JaxbEntity) {
JaxbEntity entityElement = (JaxbEntity) element;
AnnotationDescriptor entity = new AnnotationDescriptor(Entity.class);
copyAttribute(entity, "name", entityElement.getName(), false);
if (defaults.canUseJavaAnnotations() && StringHelper.isEmpty((String) entity.valueOf("name"))) {
Entity javaAnn = getPhysicalAnnotation(Entity.class);
if (javaAnn != null) {
entity.setValue("name", javaAnn.name());
}
}
return AnnotationFactory.create(entity);
} else {
// this is not an entity
return null;
}
}
}
use of jakarta.persistence.Entity in project hibernate-orm by hibernate.
the class DefaultCatalogAndSchemaTest method verifyEntityPersisterQualifiers.
private void verifyEntityPersisterQualifiers(Class<?> entityClass, ExpectedQualifier expectedQualifier) {
// The hbm.xml mapping unfortunately sets the native entity name on top of the JPA entity name,
// so many methods that allow retrieving the entity persister or entity metamodel from the entity class no longer work,
// because these methods generally assume the native entity name is the FQCN.
// Thus we use custom code.
AbstractEntityPersister persister = (AbstractEntityPersister) sessionFactory.getRuntimeMetamodels().getMappingMetamodel().streamEntityDescriptors().filter(p -> p.getMappedClass().equals(entityClass)).findFirst().orElseThrow(() -> new IllegalStateException("Cannot find persister for " + entityClass));
String jpaEntityName = sessionFactory.getRuntimeMetamodels().getJpaMetamodel().getEntities().stream().filter(p -> p.getBindableJavaType().equals(entityClass)).findFirst().orElseThrow(() -> new IllegalStateException("Cannot find entity metamodel for " + entityClass)).getName();
// Table names are what's used for Query, in particular.
verifyOnlyQualifier(persister.getTableName(), SqlType.RUNTIME, jpaEntityName, expectedQualifier);
// Here, to simplify assertions, we assume all derived entity types have:
// - an entity name prefixed with the name of their super entity type
// - the same explicit catalog and schema, if any, as their super entity type
verifyOnlyQualifier(persister.getTableNames(), SqlType.RUNTIME, jpaEntityName, expectedQualifier);
// This will include SQL generated by ID generators in some cases, which will be validated here
// because ID generators table/sequence names are prefixed with the owning entity name.
verifyOnlyQualifier(persister.getSQLInsertStrings(), SqlType.RUNTIME, jpaEntityName, expectedQualifier);
if (persister.isIdentifierAssignedByInsert()) {
verifyOnlyQualifier(persister.getSQLIdentityInsertString(), SqlType.RUNTIME, jpaEntityName, expectedQualifier);
}
try {
verifyOnlyQualifierOptional(persister.getIdentitySelectString(), SqlType.RUNTIME, jpaEntityName, expectedQualifier);
} catch (MappingException e) {
if (e.getMessage().contains("does not support identity key generation")) {
// For some reason Oracle12cIdentityColumnSupport#supportsInsertSelectIdentity() returns true,
// but getIdentitySelectString is not implemented, resulting in runtime exceptions.
// Whatever, we'll just ignore this for now.
} else {
throw e;
}
}
verifyOnlyQualifier(persister.getSQLUpdateStrings(), SqlType.RUNTIME, jpaEntityName, expectedQualifier);
verifyOnlyQualifier(persister.getSQLLazyUpdateStrings(), SqlType.RUNTIME, jpaEntityName, expectedQualifier);
verifyOnlyQualifier(persister.getSQLDeleteStrings(), SqlType.RUNTIME, jpaEntityName, expectedQualifier);
// This is used in the "select" id generator in particular.
verifyOnlyQualifierOptional(persister.getSelectByUniqueKeyString("basic"), SqlType.RUNTIME, jpaEntityName, expectedQualifier);
}
use of jakarta.persistence.Entity in project eclipselink by eclipse-ee4j.
the class TestProcessor method testProc.
private void testProc(String name, String pxml, String oxml) throws Exception {
TestFO entity = new TestFO("org.Sample", "package org; import jakarta.persistence.Entity; @Entity public class Sample { public Sample() {} public int getX() {return 1;} interface A {}}");
TestFO nonSC = new TestFO("some.IF", "package some; public class IF { public IF() {}}");
TestFO nonAnn = new TestFO("custom.Ann", "package custom; public @interface Ann { }");
TestFO nonExt = new TestFO("external.Cls", "package external; public class Cls { public Cls(){}}");
TestFO nonEntity = new TestFO("org.NotE", "package org; import jakarta.persistence.Entity; public class NotE extends some.IF { public NotE() {} @custom.Ann public external.Cls getW() {return new Object();}}");
TestFO generated8 = new TestFO("org.Gen8", "package org; import jakarta.annotation.Generated; @Generated(\"com.example.Generator\") public class Gen8 { public Gen8() {} public int getY() {return 42;}}");
TestFO generated9 = new TestFO("org.Gen9", "package org; @javax.annotation.processing.Generated(\"com.example.Generator\") public class Gen9 { public Gen9() {} public int getZ() {return 9*42;}}");
Result result = runProject(name, getJavacOptions("-Aeclipselink.logging.level.processor=OFF"), Arrays.asList(entity, nonSC, nonAnn, nonExt, nonEntity, generated8, generated9), pxml, oxml);
File outputFile = new File(result.srcOut, "org/Sample_.java");
Assert.assertTrue("Model file not generated", outputFile.exists());
Assert.assertTrue(Files.lines(outputFile.toPath()).anyMatch(s -> s.contains("@StaticMetamodel(Sample.class)")));
}
use of jakarta.persistence.Entity in project eclipselink by eclipse-ee4j.
the class TestProcessor method testTypeUse.
public void testTypeUse(String name, String pxml, String oxml) throws Exception {
TestFO entity = new TestFO("org.Ent", "package org; @jakarta.persistence.Entity public class Ent { @org.ann.NotNull private byte[] bytes;}");
TestFO ann = new TestFO("org.ann.NotNull", "package org.ann; @java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) public @interface NotNull {}");
Result result = runProject(name, getJavacOptions("-Aeclipselink.logging.level.processor=OFF"), Arrays.asList(entity, ann), pxml, oxml);
File outputFile = new File(result.srcOut, "org/Ent_.java");
Assert.assertTrue("Model file not generated", outputFile.exists());
Assert.assertTrue(Files.lines(outputFile.toPath()).noneMatch(s -> s.contains("NotNull")));
Assert.assertTrue("Compilation failed", result.success);
}
Aggregations