Ensure the class is annotated with Introspected - jhipster

My class:
/**
* A Customer.
*/
#Entity
#Table(name = "customer")
#Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
#Audited
#Introspected
public class Customer implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
#NotNull
#Type(type = "uuid-char")
#Column(name = "uuid", length = 36, nullable = false, unique = true)
private UUID uuid;
}
I call:
Customer result = customerRepository.save(cust);
Even if I use #Introspected annotation in my Pojo class Customer, Error I get:
Unexpected error occurred: Unable to perform beforeTransactionCompletion callback: No bean introspection available for type [class org.hibernate.envers.DefaultRevisionEntity]. Ensure the class is annotated with io.micronaut.core.annotation.Introspected
All tables related audit is created.
Using Jhipster + Micronaut + Hibernate Envers
Below is my setup info:
MHipster v1.0.2 :: Running Micronaut v2.4.4
JHipster version: 6.10.5

Related

ModelMapper failed to convert java.lang.String to java.lang.Long

I have rest models that I use to build JSON that I send.
A rest model
#Getter #Setter
#ToString
public class OrderRequestModel {
private String orderKeyId;
private String paymentMode;
private double totalAmount;
private List<ProductRequestModel> orderProducts;
private UserDetailsRequestModel seller;
private Date createdAt;
}
The ProductRequestModel is similar
#Getter #Setter
#ToString
public class ProductRequestModel {
private String productKeyId;
private String name;
private double price;
private int qty;
private String imgPath;
private CategoryRequestModel category;
}
I'm passing the models to a DTO layer which is in relation with database (they include a long Id):
#Getter #Setter
#ToString
public class OrderDto implements Serializable {
#Getter(AccessLevel.NONE)
#Setter(AccessLevel.NONE)
private static final long serialVersionUID = 1L;
private Long id;
private String orderKeyId;
private String paymentMode;
private double totalAmount;
private List<ProductDto> orderProducts;
private UserDto seller;
private Date createdAt;
}
And my ProductDto :
#Getter #Setter
#ToString
public class ProductDto implements Serializable {
// ommit this member and do not generate getter / setter
#Getter(AccessLevel.NONE)
#Setter(AccessLevel.NONE)
private static final long serialVersionUID = 1L;
private Long id;
private String productKeyId;
private String name;
private double price;
private int qty;
private String imgPath;
private CategoryDto category = new CategoryDto();
}
When i try to map OrderDto with the associated model i do it implicitelly :
OrderDto orderDto = modelMapper.map(orderRequestModel, OrderDto.class);
In theory, orderKeyId from the model should match with its equivalent in the Dto. Unfortunatelly It returns an error :
Converter org.modelmapper.internal.converter.NumberConverter#3e36f4cc failed to convert java.lang.String to java.lang.Long.
Caused by: org.modelmapper.MappingException: ModelMapper mapping errors:
I do need the Id in the DTO because if i want to make an update I do use "id"
This issue is caused because of the Mapping Strategies. We can set the Mapping Strategies to STRICT so that when mapping from source object property to target object's property it only maps only those property which are perfectly matching in property name as well as it's data type. Below is an example.
public ModelMapper modelMapper() {
ModelMapper modelMapper = new ModelMapper();
modelMapper.getConfiguration()
.setMatchingStrategy(MatchingStrategies.STRICT);
}
FYI:
http://modelmapper.org/user-manual/configuration/#matching-strategies

CDI Injected Bean from super class has null fields in child

I'm pretty new to the general procedure of bean injection. I've googled a lot but haven't found a solution to my problem.
Additional Information
Running Wildfly 9.0.1 final
EJB Vers. : 3.1
CDI Vers. : 2.2.16 (SP1)
JSF Vers. : 2.2
import javax.annotation.PostConstruct;
import javax.ejb.Stateless;
import javax.inject.Named;
#Named
#ViewScoped
public class UserEmailSettingsBean extends UserModuleSettingsBean {
private List<String> store;
private List<String> selectedStore;
//getters and setters, some fancy stuff...
#Override
public boolean saveProperties() {
LOG.info("Save called");
LOG.info(selectedStore.toString());
LOG.info(store.toString());
for(String prop : store) {
getProperties().setProperty(prop, String.valueOf(false));
}
for(String selectedProp : selectedStore){
LOG.info("selected: " + selectedProp + ":" + getProperties().getProperty(selectedProp) + " -> true");
getProperties().setProperty(selectedProp, String.valueOf(true));
}
super.saveProperties();
return true;
}
}
2nd Class:
public abstract class UserModuleSettingsBean implements ModuleSettings {
private static final long serialVersionUID = 459417872482285085L;
protected abstract List<String> getPropertiesName();
#Inject
private SettingsRepository settingsRepository;
#Inject
private SettingsService settingsService;
private Properties properties = new Properties();
#Override
public boolean saveProperties() {
String username = SecurityContextHolder.getContext().getAuthentication().getName();
settingsService.store(getProperties(), username);
return (true);
}
}
The problem is, that the settingsService is constructed, however its field "settingsRepository" is null in my child class.
On the call of my save method from UserEmailSettings, getProperties().setProperty() is called with the right values, however its never stored, as the settingsRepository is null. I believe that is due to a wrong Injection for some reason.
Let me know if I need to provide more information ☺
Here is the needed part of SettingsRepository:
#Stateless
#TransactionAttribute(TransactionAttributeType.SUPPORTS)
public class SettingsService implements Serializable {
private static final long serialVersionUID = 1695882717866085259L;
#Inject
SettingsRepository settingsRepository;
//...
}
And here the information SettingsRepository
#Stateless
public class SettingsRepository extends AbstractBaseRepository<Settings, Long> {
/**
* Instantiates a new settings repository.
*/
public SettingsRepository() {
super(Settings.class);
}
}
wanted to say my problem was that I didn't called an init() function on the settingsService to create the propertys, so getProperties was empty

Value 0 of type class java.util.LinkedHashMap does not correspond to any CQL3 type

I'm trying to save a spring entity to Cassandra (2.0.11) using a Cassandra repository. The entity class is as follows:
#Table(value="gs")
public class GsJsonStore implements Serializable {
private static final long serialVersionUID = 7133072282172062535L;
#PrimaryKey
private String id;
#Column(value = "object")
#CassandraType(type=DataType.Name.MAP)
private Map<String, String> _object;
#Column(value = "subject")
private String _subject;
//Getter and Setter methods.
}
The code I'm using to save the object:
GsJsonStore gsJsonStore = new GsJsonStore();
gsJsonStore.setPredicate("Predicate");
gsJsonStore.setSubject("Subject");
gsJsonStore.setObject(jsonToMap(jsonNode));
repository.save(gsJsonStore);
The jsonToMap function:
public Map<String,String> jsonToMap(JsonNode json) {
ObjectMapper mapper = new ObjectMapper();
Map<String, String> result = mapper.convertValue(json, Map.class);
return result;
}
I get the following error while storing the object:
java.lang.IllegalArgumentException:
Value 0 of type class java.util.LinkedHashMap does not correspond to any CQL3 type
Where am I going wrong?

GlassFish ManagedBeanCreationException and NullPointerException

I have written an EJB and a dynamic web project Eclipse on GlassFish server. I used DAO , Facade and JPA. Normally I am calling a method from my service it is giving these errors ;
kitapOduncVerme.xhtml]com.sun.faces.mgbean.ManagedBeanCreationException
PWC1406: Servlet.service() for servlet Faces Servlet threw exceptionjava.lang.NullPointerException
at com.mesutemre.kitapislemleri.KitapOduncVermeBean.initList(KitapOduncVermeBean.java:47)
at com.mesutemre.kitapislemleri.KitapOduncVermeBean.initialize(KitapOduncVermeBean.java:43)
My codes are below;
#ManagedBean(name = "oduncKitapVerBean")
#ViewScoped
public class KitapOduncVermeBean implements Serializable{
private static final long serialVersionUID = 1L;
private List<Kitaplar> entityList = new ArrayList<Kitaplar>();
private Kitaplar selectedEntity;
private Kitaplar entity;
private String kullaniciadi;
private KitaplarFacade service;
public KitapOduncVermeBean() {
entity = new Kitaplar();
selectedEntity = new Kitaplar();
}
#PostConstruct
public void initialize(){
HttpSession session = Util.getSession();
kullaniciadi = Util.getUserName();
initList();
}
private void initList(){
entityList = service.findAllKitaplar();
}
DaoImpl
#SuppressWarnings("unchecked")
public List<Kitaplar> findAllKitaplar(){
return em.createNamedQuery("tumkitaplarigetir").getResultList();
}
Dao
#Stateless
#LocalBean
public class KitaplarDAO extends KitaplarDaoImpl<Kitaplar> implements Serializable{
private static final long serialVersionUID = 1L;
#Override
public List<Kitaplar> findAllKitaplar() {
return super.findAllKitaplar();
}
FacadeImpl
#Stateless
#LocalBean
public class KitaplarFacadeImpl implements KitaplarFacade,Serializable {
private static final long serialVersionUID = 1L;
#EJB
KitaplarDAO kitapDao;
#Override
public List<Kitaplar> findAllKitaplar() {
return kitapDao.findAllKitaplar();
}
}
Facade
#Local
public interface KitaplarFacade {
public abstract List<Kitaplar> findAllKitaplar();
}
I can't see any problem in this codes? But Why am I getting that errors?
ManagedBeanCrearionException is simply wrapping and rethrowing the NullPointerException, that is very easy to debug: you have a null variable at the exact line that appears in the stack trace.
In KitapOduncVermeBean class, you are declaring service property, but you are not initializing it, therefore it's null when invoked in initList() method. Since it's an EJB, annotate it as such and the EJB container will instantiate it automatically:
#EJB
private KitaplarFacade service;
Unrelated to the concrete problem, your code is too complicated: with EJB 3.x, in most web applications, you don't need EJBs to implement or expose interfaces.

NullPointerException in JSF Converter

I have a table Users and Specializations in database
Users:
CREATE TABLE IF NOT EXISTS `ePrzychodnia`.`users` (
`id` INT NOT NULL AUTO_INCREMENT ,
`firstName` VARCHAR(45) NOT NULL ,
`lastName` VARCHAR(45) NOT NULL ,
`specialization_id` INT NULL ,
PRIMARY KEY (`id`) ,
UNIQUE INDEX `personalId_UNIQUE` (`personalId` ASC) ,
INDEX `fk_users_specializations1_idx` (`specialization_id` ASC) ,
CONSTRAINT `fk_users_specializations1`
FOREIGN KEY (`specialization_id` )
REFERENCES `ePrzychodnia`.`specializations` (`id` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
Specializations:
CREATE TABLE IF NOT EXISTS `ePrzychodnia`.`specializations` (
`id` INT NOT NULL ,
`name` VARCHAR(45) NOT NULL ,
PRIMARY KEY (`id`) ,
UNIQUE INDEX `name_UNIQUE` (`name` ASC) )
ENGINE = InnoDB;
Entity class:
Users:
public class User implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Basic(optional = false)
#Column(name = "id")
private Integer id;
#Basic(optional = false)
#NotNull
#Size(min = 1, max = 45)
#Column(name = "firstName")
private String firstName;
#Basic(optional = false)
#NotNull
#Size(min = 1, max = 45)
#Column(name = "lastName")
private String lastName;
#Basic(optional = false)
#JoinColumn(name = "specialization_id", referencedColumnName = "id")
#ManyToOne
private Specialization specializationId;
Specialization:
public class Specialization implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#Basic(optional = false)
#NotNull
#Column(name = "id")
private Integer id;
#Basic(optional = false)
#NotNull
#Size(min = 1, max = 45)
#Column(name = "name")
private String name;
#OneToMany(mappedBy = "specializationId")
private Collection<User> userCollection;
and I try create converter to one select menu in JSF:
SelectOneMenu:
<h:outputLabel for="specialization" value="#{msg.specialization}"/>
<p:selectOneMenu id="specialization" value="#{userMB.user.specializationId}" effect="fade" style="width:200px" converter="specializationConverter">
<f:selectItems value="#{specializationMB.allSpecialization}" var="specialization" itemValue="#{specialization}" itemLabel="#{specialization.name}"/>
</p:selectOneMenu>
<p:message for="specialization"/>
and Converter:
public class SpecializationConverter implements Converter{
private SpecializationDao specializationDao = new SpecializationDao();
#Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
Integer id = Integer.parseInt(value);
return specializationDao.find(id);
}
#Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
return ((Specialization) value).getId().toString();
}
}
But convertert dont work;/ I have a error:
WARNING: StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception
java.lang.NullPointerException
at pl.Project.dao.SpecializationDao.find(SpecializationDao.java:36)
at pl.Project.converter.SpecializationConverter.getAsObject(SpecializationConverter.java:29)
SpecializationDao:
#Stateless
public class SpecializationDao implements SpecializationDaoLocal {
#PersistenceContext
private EntityManager em;
private Specialization specialization;
public SpecializationDao() {
}
public SpecializationDao(Specialization specialization) {
this.specialization = specialization;
}
#Override
public Specialization find(int specializationId) {
return em.find(Specialization.class, specializationId);
}
#Override
public List<Specialization> findAllSpecialization() {
Query q = em.createNamedQuery("Specialization.findAll");
List<Specialization> specializations = q.getResultList();
return specializations;
}
}

Resources