This content has been marked as final.
Show 4 replies
-
1. Re: Entity name
lightguard Nov 8, 2011 12:37 PM (in response to tschleuss)What are you trying to do? I'm not sure what you are trying to do with this.
That class is not in Seam 3, in fact, most of the classes from Seam 2 are not in Seam 3.
-
2. Re: Entity name
tschleuss Nov 8, 2011 1:23 PM (in response to tschleuss)We have used this code to retrieve the entity name to make some queries.
But i'm make a EntityUtils with some codes do replace seam 2 facilities :)
I don't know if is the beast solution, but works.public static String getEntityName(final Class<?> clazz) { String name = null; if (EntityUtils.isEntity(clazz)) { Entity entity = clazz.getAnnotation(Entity.class); if (!entity.name().isEmpty()) { name = entity.name(); } else { name = clazz.getName(); } } return name; }
public static boolean isEntity(final Class<?> clazz) { if (EntityUtils.isSerializable(clazz)) { return clazz.isAnnotationPresent(Entity.class); } return false; }
public static boolean isSerializable(final Class<?> clazz) { if (clazz.getInterfaces() != null) { for (Class<?> subClz : clazz.getInterfaces()) { if (subClz == Serializable.class) { return true; } } } return (clazz.getSuperclass() != null) ? isSerializable(clazz .getSuperclass()) : false; }
Thanks anyway.
-
3. Re: Entity name
lightguard Nov 8, 2011 3:31 PM (in response to tschleuss)Try this stackoverflow question for a better way to check for serializable. The rest look like they're okay. Take a look at the JPA 2.0 API Metamodel for some other ideas on how to test for some of the entity stuff you're looking for.
-