Here is my entity class.
#Entity
public class Store implements Serializable {
private static final long serialVersionUID = 1L;
public Store() {
}
#Id
private int id;
private String code;
private String password;
private String forgetPasswordNote;
private String key;
private String ownerId;
private String storeLink;
private String activationCode;
private String name;
private String homepageUrl;
private String sessionToken;
private Date dateCreated;
private Date expireDate;
private Date lastModified;
private String nmPassword;
private String storeType;
private String premium;
private double money;
private boolean refreshed;
private String country;
private String lang;
private String varId;
private String fbPageId;
private boolean fbEnabled;
private boolean informative;
private boolean active;
private String fbEnabledBy;
private String ipAddress;
private String comments;
private float commission;
private String picasaEmail;
// all getter and setter goes here
}
Here is my controller
#Controller
public class RegController {
#RequestMapping(value = "/create/database")
public String createDatabase(ModelMap map, HttpServletRequest request) {
Store store = new Store();
store.setId(1);
store.setCode("1");
System.out.println("test worl");
#SuppressWarnings("deprecation")
SessionFactory sessionFactory = new Configuration().configure()
.buildSessionFactory();
try {
Session session = sessionFactory.openSession();
session.beginTransaction();
session.save(store);
session.getTransaction().commit();
session.close();
} catch (Exception e) {
System.out.println(e.toString());
}
return "home";
}
}
When I run the url localhost:8080/MyApp/create/database I am getting and error. org.hibernate.exception.SQLGrammarException: could not execute statement
Is there any reserved keyword on my entites class?
I have found the solution key is reserved keyword on mysql database so I simply change the key to storekey and everything work fine.
Related
public class MessageRqDTO implements Serializable {
private Long id;
private String data;
private String device;
private String headers;
private Boolean isProcessed;
private String notification;
private String referenceCode;
private Boolean scheduled;
private Boolean transactional;
private Instant startFromTime;
private Instant expirationTime;
private List<String> identifiers = new ArrayList<>();
private UserTokenDTO userToken;
}
first dto List identifiers
public class MessagetoMqDTO implements Serializable{
private Long id;
private String data;
private String device;
private String headers;
private Boolean isProcessed;
private String notification;
private String referenceCode;
private Boolean scheduled;
private Boolean transactional;
private Instant startFromTime;
private Instant expirationTime;
private String identifiers ;
private UserTokenDTO userToken;
private String clientToken;
}
second DTO
use this
#Mapping(target = "messageDTO", source = "messageDTO")
MessagetoMqDTO toDto(MessageRqDTO m,String identifier,String clientToken);
Error:
java: Can't map property "String identifiers" to "List<String> identifiers". Consider to declare/implement a mapping method: "List<String> map(String value)".
Add this method to your mapper interface:
default String mapIdentifiers(List<String> identifiers){
String identifiersSeparator = ",";
return identifiers.stream().collect(Collectors.joining(identifiersSeparator));
}
1-this my model object for account , iwant to return a json result for post method and my problem that my code return null .=
public class Account implements Serializable {
private static final long serialVersionUID = 1L;
private long id;
private String accountType;
private String title;
private double lockedAmount;
private String lastUpdate;
private double balance;
private String currency;
private String rib;
private String Agency;
private String swiftcode;
private String ribURI;
private boolean canDebit;
private boolean canCredit;
private List<Operation> operation;
private List<Documents> documents;
2-this the class Operation :
public class Operation {
private String Descript;
private String ValueDate;
private String bookDate;
private String Reference;
private Integer Debit;
private Integer Credit;
private Integer ClosingBalance;
}
3-this is what i do in my controller :
//get Operation list by account id
#PostMapping("eAccount/Operations/Account/{id}")
public List<Operation> getOperationsByAccountId(#PathVariable long id, String bookDate) {
return operationService.getOperationsByAccountId(id, bookDate);
}
4-and the service :
//get Operation list by account id
public List<Operation> getOperationsByAccountId(#PathVariable long id, String bookDate) {
Account account = new Account();
account.setId(id);
String url = operationUrl;
account = resttemplate.postForObject(url,account, Account.class);
return account.getOperation();
}
5-i need to return this result :
{ "account": { "id": "100000000137",
"operation": [
{
"bookDate": "20160105 20160201" } ] } }
#Service
#Transactional
#RequiredArgsConstructor
public class HTMLParser {
public static final String link1;
public static final String link2;
public final String url;
private final #NonNull VillageRepository;
public void parseLink(String link, String selektor){
// 1. úroven - získej z hlavního odkazu všechny obce nutné k proklikání
try {
Document doc = Jsoup.connect(link).get();
Elements links = doc.select(selektor);
for (Element alink : links) {
System.out.println("text: " + alink.text());
parseLink(vytvořURL(alink.attr("href")), "div.sloupec3 a");
}
if(links.isEmpty()){
links = doc.select("dl.sloupec dd");
Village village = extractInformation(links);
obecRepository.saveAndFlush(obec);
}
} catch (IOException e) {
e.printStackTrace();
}
}
public void parseLink(String link, String selektor){
try {
Document doc = Jsoup.connect(link).get();
Elements links = doc.select(selektor);
for (Element alink : links) {
parseLink(createURL(alink.attr("href")), "div.sloupec3 a");
}
if(links.isEmpty()){
links = doc.select("h4.navigace a");
Set<String> hiearchie = extractHiearchy(links);
Iterator<String> iterator = hiearchie.iterator();
links = doc.select("dl.sloupec dd");
Village village = extractInfo(links);
villageRepository.saveAndFlush(village );
}
} catch (IOException e) {
e.printStackTrace();
}
}
private Village extractInfo(Elements elements){
if(elements.size() != 13){
elements.add(3, new Element("<dd><span class=\"sede\">--- ---</span></dd>"));
}
Village village = new Village(Long.parseLong(elements.get(7).text()), elements.get(0).text(), elements.get(1).text(),
elements.get(2).text(), elements.get(3).text(), elements.get(5).text(), elements.get(6).text(),
elements.get(8).text(), getHours(elements.last()));
village.setEmails(extrahjZBloku(elements.get(9)));
village.setWWW(extrahjZBloku(elements.get(10)));
village.setPhones(extrahujTelefony(elements.get(11)));
village.setAccounts(extrahujÚčetAIBAN(elements.get(4)));
return village;
}
#Entity
#Getter
#Setter
public class Village {
public Village (){}
#Id
private long code;
#Column
private String type;
#Column(name = "name")
private String name;
#Column
private String adress;
#Column(name = "sec_adress")
private String secAdress;
#Column(name = "bank")
private String bank1;
#Column(name = "bankovní_spojení2")
private String bank2;
#Column
private String IBAN1;
#Column
private String IBAN2;
#Column
private String IC;
#Column
private String DIC;
#Column
private String shortcut;
#Column
private String email1;
#Column
private String email2;
#Column
private String email3;
#Column
private String email4;
#Column
private String www1;
#Column
private String www2;
#Column
private String www3;
#Column
private String www4;
#Column
private String telefon1;
#Column
private String telefon2;
#Column
private String telefon3;
#Column
private String telefon4;
#Lob
#Column(name = "hours")
private String hours;
}
public interface VillageRepository extends JpaRepository<Village, Long> {
}
My problem is that object village in the method parseLink does not save to the database... nothing happens and not even error shows up... When I try to save that object in the main method with with test parameters, it works, but not where I need... When I try to save something different in that method, nothing also happens, so the problem must be in the method parseHTML i guess
Thanks for help
PS: In intelij, i can see created insert command which seems to OK, but nothing is in the database...
Try putting the #Transactional annotation on the public functions, instead of the class.
I do not know how you really distributed into classes, but is it your JpaRepository decorated with the annotation #Repository ??
I am not able to fetch all records from two tables using the below query
I have tried this but I am getting a result from one table only. I want a result of both the tables i.e, client_software_param_mapping and client_file_configuration having the same ClientId which is a foreign key from third pojo(client_software_configuration) to first and second pojo.
public Result showClientConfiguration() {EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("defaultPU");
EntityManager entityManager = entityManagerFactory.createEntityManager();
Query q=entityManager.
createQuery("SELECT c FROM client_software_param_mapping c JOIN fetch client_file_configuration f ON c.ClientId=f.ClientId");
List data =q.getResultList();
return ok(Json.toJson(data));
}
first pojo
#Entity
public class client_file_configuration {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String sourceFolder;
private String sourceFile;
private String processingFolder;
private String processingFile;
private String processedFolder;
private int intervalInMin;
private String readAfterDelay;
private String parserClass;
private String directoryMode;
private String fileMode;
private String actionMode;
private String type;
private String fileExpressionResolver;
#OneToOne
#JoinColumn(name = "ClientId")
private client_software_configuration clientSoftwareConfiguration;
public client_software_configuration getClientSoftwareConfiguration() {
return clientSoftwareConfiguration;
}
public void setClientSoftwareConfiguration(client_software_configuration clientSoftwareConfiguration) {
this.clientSoftwareConfiguration = clientSoftwareConfiguration;
}
}
secondpojo
#Entity
public class client_software_param_mapping {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String paramKey;
private String paramValue;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getParamKey() {
return paramKey;
}
public void setParamKey(String paramKey) {
this.paramKey = paramKey;
}
public String getParamValue() {
return paramValue;
}
public void setParamValue(String paramValue) {
this.paramValue = paramValue;
}
#ManyToOne
#JoinColumn(name = "ClientId")
private client_software_configuration clientSoftwareConfiguration;
public client_software_configuration getClientSoftwareConfiguration() {
return clientSoftwareConfiguration;
}
public void setClientSoftwareConfiguration(client_software_configuration clientSoftwareConfiguration) {
this.clientSoftwareConfiguration = clientSoftwareConfiguration;
}
}
thirdpojo
#Entity
public class client_software_configuration {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String url;
private int port;
private String endPoint;
private String isPost;
private String isPing;
private String params;
private int serialNo;
private String dateFormat;
private String token;
}
this is the right query as it is returning the object of the third pojo present at that ClientId so it is able to understand the type of ClientId.JPQL never uses table and column names. It always uses entity names and their mapped fields/properties names.so here I have taken the object of the third pojo having the ClientId field.
select c,p from client_file_configuration c,client_software_param_mapping p where c.clientSoftwareConfiguration = p.clientSoftwareConfiguration
I am using realm in my project with the following model class
#Data
#Type("user")
#Builder()
#NoArgsConstructor
#AllArgsConstructor
#EqualsAndHashCode(of = {"id", "email"}, callSuper = true)
#JsonNaming(PropertyNamingStrategy.KebabCaseStrategy.class)
public class User extends RealmObject {
#PrimaryKey
#Id(IntegerIdHandler.class)
private int id;
private String firstName;
private String lastName;
private String email;
#Ignore
private String password;
private boolean isAdmin;
private boolean isSuperAdmin;
private String createdAt;
private String lastAccessedAt;
private String contact;
private String deletedAt;
private String details;
private boolean isVerified;
private String thumbnailImageUrl;
private String iconImageUrl;
private String smallImageUrl;
private String avatarUrl;
private String facebookUrl;
private String twitterUrl;
private String instagramUrl;
private String googlePlusUrl;
private String originalImageUrl;
}
Most of those annotations are from lombok.
When I run my project, I get the following error
Error:(149, 20) error: realmGet$id() in org_fossasia_openevent_core_auth_model_UserRealmProxy cannot override realmGet$id() in User
return type Integer is not compatible with int
The weird part is that this error arises from realm generated code.
Any suggestions?