Problem with DiscriminatorValue - The abstract schema is unknown - jpa

I must run project with JEE and EclipseLink 2.6.1. Maven successfully compiles the project, but when I put . jar on Payara and try to run it it gets problems of the type:
The abstract schema type 'NetServer'; is unknown.
The state field path 'netserver.active'; cannot be resolved to a valid type.
The problem occurs in queries with all entities with annotations #DiscriminatorValue. Entity looks like this:
Main class (Servers) :
#Entity
#Table("Servers")
#DiscriminatorColumn(
name = "SERVER_TYPE",
discriminatorType = DiscriminatorType.STRING
)
#DiscriminatorValue("servers")
public class Servers{
#Id
private Long id;
private String name;
private String hostname;
private Boolean active;
//getters& setters
}
Netserver:
#Entity
#DiscriminatorValue("netserver")
public class NetServer extends Server{
private String url;
public Netserver();
public Netserver(Server server){super(server);}
//getters&setters
}
And I wonder what the problem is that he throws away exceptions?

Related

Spring Boot Cassandra Error connecting to Node(endPoint=localhost:1234, hostId=null, hashCode=37hfeouh3),

In my Spring Boot Cassandra build I am getting the following error: s0-admin-1] c.d.o.d.i.c.control.ControlConnection : [s0] Error connecting to Node(endPoint=localhost:1234, hostId=null, hashCode=37hfeouh3), trying next node (ConnectionInitException: [s0|control|connecting...] Protocol initialization request, step 1 (OPTIONS): failed to send request (io.netty.channel.StacklessClosedChannelException))
Entity type of
#Data
#Builder
#Table
public class Class1 {
#Id
private String id;
private String data;
private Class2 data2;
private Integer data3;
...
}
public class2 Class2 {
#Id
#JasonProperty
private String id;
#Indexed
#JasonProperty
private String data;
#JasonProperty
private String data2;
#JasonProperty
private Integer data3;
...
}
#Configuration
#EnableCassandraRepositories
#ConfigurationProperties(prefix = "DBProperties")
public class ApplicationConfig extends AbstractCassandraConfiguration {
private String DBKEYSPACE;
#Override
protected String getKeyspaceName() {
return DBKEYSPACE;
}
public String[] getEntityBasePackages() {
return new String[] { "com.oreilly.springdata.cassandra" };
}
}
#ConfigurationProperties(prefix = "DBPROPERTIES")
#Slf4j
public class FactoryBeanAppConfig {
private String contactPoints;
private String keySpace;
private Integer port;
private String password;
private String username;
private String dataCenter;
/*
* Factory bean that creates the com.datastax.oss.driver.api.core.CqlSession instance
*/
#Bean
public CqlSessionFactoryBean session() {
//log it we made it.
log.info("I made it to CqlSessionFactoryBean");
CqlSessionFactoryBean session = new CqlSessionFactoryBean();
session.setContactPoints(URLINFO);
log.info("Contact Points: " +URLINFO);
session.setKeyspaceName(DBKEYSPACE);
//session.setPort(OURPORT);
session.setUsername(username);
session.setPassword(password);
session.setLocalDatacenter(LOCALDCENTER INFORMATION);
return session;
}
}
I am unable to find a good example or even a get it to work correctly. Looking at this documentation: https://docs.spring.io/spring-data/cassandra/docs/current/reference/html/#cassandra.core thats the only thing I should have to do to implement example 55
For the spring boot run your application, it need to load the DB when your server application (the tomcat for example) is starting. So, your schema should be created first. If it is ok, you could change the "localhost" to "127.0.0.1" in your cassandra.yaml file.
Important: "[s0] Error connecting to Node(endPoint=localhost:1234,..." please check the cassandra's port. The correct is 9042.
It will solve your problem. However, others errors can be happen, because the others classes.
Then, you could correct the classes below:
#SpringBootApplication
#EnableCassandraRepositories(basePackages = { "<package's path>" })
#EntityScan(basePackages = { "<package's path>" })
#ComponentScan(basePackages = { "<package's path>" })
public class ApplicationConfig extends SpringBootServletInitializer
{
SpringApplication.run(ApplicationConfig.class, args);
}
Entity:
#Table("<table name>")
public class Class1 {
#PrimaryKeyColumn(name = "<field name id>", type = PrimaryKeyType.PARTITIONED)
private String id;
#Column("<field name data>")
private String data;
private Class2 data2; //I think this declaretion can cause error
#Column("<field name data3>")
private Integer data3;
...
}
This FactoryBeanAppConfig's class is not sound good. I created a class to read the application.properties and inject this class to connect with the db datas like keyspace's name, port, and so one. This link will help you to creat this class: https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config . And then, you use this class in your FactoryBeanAppConfig's class to get DBKEYSPACE, OURPORT, ... .
This is a example to helps you to understand what I'm saying: https://www.baeldung.com/spring-data-cassandra-tutorial .

Upgrading from Spring Data 1.11 to Spring Data 2.0 results in "No property delete found for type SimpleEntity!"

I have a simple project with the classes below defined. It works just fine in spring-boot 1.5.4, spring-data-commons 1.13, and spring-data-jpa 1.11.
When I upgrade to spring-boot 2.0.0.M5, spring-data-commons 2.0.0 and spring-data-jpa-2.0.0, I get a PropertyReferenceException at startup that says "No property delete found for type SimpleEntity!" Unfortunately, I can't get the stack trace out of
the computer I get the error in, it is very locked down for security.
Any ideas? Other posts I found don't seem to match my situation.
Here are the classes (altered the names, but you get the idea):
package entity;
#MappedSuperclass
public abstract class BaseEntity implements Serializable {
....
}
package entity;
#Entity
#Table(schema = "ENTITIES", name = "SIMPLE")
public class SimpleEntity extends BaseEntity {
#Column(name = "ID")
private Long id;
#Column(name = "CODE")
private String code;
#Column(name = "NAME")
private String name;
... getters and setters ...
}
package repository;
imoport org.springframework.data.repository.Repository
public interface SimpleRepository extends Repository<SimpleEntity, Long> {
public SimpleEntity save(SimpleEntity entity);
public List<SimpleEntity> save(List<SimpleEntity> entities);
public void delete(Long id);
public SimpleEntity findOne(Long id);
public List<SimpleEntity> findAllByOrderByNameAsc();
public List<SimpleEntity> findByCode(String code);
public List<SimpleEntity> findByNameIgnoreCaseOrderByNameAsc(String name);
}
Turns out there is a breaking change in Spring Data 2.0 CrudRepository interface. The error I received occurs under the following conditions:
You have a 1.x Sping Data project
You have an interface that extends Repository directly, not a subinterface like CrudRepository
Your Repository subinterface declares the "void delete(ID)" method found in CrudRepository (in my case "void delete(Long)"
You update to Spring Data 2.x
The problem is that CrudRepository in 2.x no longer has a "void delete(ID)" method, it was removed, and a new method "void deleteById(ID)" was added.
When Spring data sees a delete method signature it doesn't recognize, it produces an error about your entity class missing a delete property - this is true of both 1.2 and 2.x.

Json custom deserializer not called in Websphere

I have simple class and field id is annotated with custom deserializer.
public class TestRequest implements Serializable {
#NotNull
#Pattern(regexp = "^[a-zA-Z0-9=+]*$")
#JsonDeserialize(using = StringDeserializer.class)
#JsonProperty
private String id;
//getter
//setter
}
and the custom deserializer class :
public class StringDeserializer extends JsonDeserializer<String> {
#Override
public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) {
Iterator<String> iterator = jsonParser.readValuesAs(String.class);
String id = iterator.next();
return id + "0000";
}
}
When i test with with Jersey REST test, the deserilizer is called and works as expected. But with websphere it does not called. Any idea why its not called.
I am using jaxrs 1.1
You may need to add the #Provider annotation to your StringDeserializer class, otherwise the JAX-RS runtime will not recognize the class as a provdier.
Even though your class extends JsonDeserializer<String>, which itself is probably annotated with #Provider, the JAX-RS runtime will not scan libraries for annotations, as doing negatively impacts performance.
I made it working in Websphere by moving the annotation #JsonDeserialize(using = StringDeserializer.class) to setter method of the class
public class TestRequest implements Serializable {
#NotNull
#Pattern(regexp = "^[a-zA-Z0-9=+]*$")
#JsonProperty
private String id;
#JsonDeserialize(using = StringDeserializer.class)
public setId(String id){
this.id=id;
}
//getter
//setter
}

Validating a Spring ResourceSupport-ed parent resource as a not empty property in a child resource

I'm looking for guidelines into validating a parent admin resource (AdminResource extending the Spring ResourceSupport class) as not being empty (#NotEmpty) in a child admin module resource (AdminModuleResource extending the Spring ResourceSupport class).
I understand the AdminResource class should also implement the Serializable interface ? Is that the way to go with Spring ResourceSupport-ed resources ?
Here are my resources:
public class AdminResource extends AbstractResource {
private String firstname;
private String lastname;
#NotEmpty
#Email
private String email;
private String password;
private String passwordSalt;
}
public class AdminModuleResource extends AbstractResource {
#NotEmpty
private String module;
#NotEmpty
private AdminResource adminResource;
}
public abstract class AbstractResource extends ResourceSupport {
#JsonProperty("id")
private Long resourceId;
public AbstractResource() {
}
public Long getResourceId() {
return resourceId;
}
public void setResourceId(Long resourceId) {
this.resourceId = resourceId;
}
}
As of now, the #NotEmpty validator annotation gives me the error: No validator could be found for type...
But adding the "implements Serializable" to the resources did not help and the exception remained when using the #NotEmpty validator annotation.
public abstract class AbstractResource extends ResourceSupport implements Serializable {
}
Of course, commenting out the #NotEmpty validator annotation makes the Maven build successful.
Thanks for any directions tips !
Kind Regards,
Stephane
#NotEmpty is only supported for CharSequences (String), Collections, Maps and arrays. It either checks whether the string or collection/array is empty. What does it even mean that a AdminResource is not empty. Do you mean #NotNull?
If it really would make semantically sense to have a #NotEmpty for AdminResource, you would have to implement a custom ConstraintValidator for it and registering it via XML (see also http://beanvalidation.org/1.1/spec/#xml-mapping-constraintdefinition).

Using GWT with Morphia/MongoDB

I was wondering if anyone has attempted and been successful at using the Morphia jar for interacting with a mongodb database inside of GWT? I've been using the below object as the base for all my POJO's, however whenever I attempt to save down the object using an UpdateOperations<DerivedPersistentEntity> or datastore.Save() I get a ConcurrentModificationException.
package com.greycells.dateone.shared;
import com.google.code.morphia.annotations.Id;
import com.google.code.morphia.annotations.Version;
public class PersistentEntity {
#Id
private String id;
#Version
private Long version = null;
public PersistentEntity() {
}
public String getId() {
return id;
}
public Long getVersion() {
return version;
}
public void setVersion(Long version) {
this.version = version;
}
}
I've also added the gwt extension jar that you have to download separately for Morphia and referenced it in my gwt.xml and this seems to be of no help. Additionally I've tried changing the id field of PersistentEntity to the ObjectId type but then I can't even get my project to bind correctly because it complains of...
[ERROR] No source code is available for type org.bson.types.ObjectId; did you forget to inherit a required module?
You can't use a String for the #Id field of the entity in Morphia it must be an ObjectId. GWT support in Morphia is completely broken as of v1.02.