JPAAppender blob - java

I am testing the log4j JPAAppender these days. After hours of work, I encountered just as same problem as others did.(if you search for JPAAppender, you will get that the log4j JPAAppender got a bug which keeps persisting garbage of a column of blob in size is huge for database). After that, I tried to download the source code from its official website and rewrote my own code which has exactly same class name and all the same functions in source code apart from a tiny modify I made to avoid entitymanager persisting garbage into database.
#Transient
private final LogEvent wrappedEvent;
here it is as you can find in log4j 2.7,package
package org.apache.logging.log4j.core.appender.db.jpa;
After doing that with full of hope that I might make it right, I ran my application and I got this error:
2018-01-29 17:18:44,543 main ERROR Entity class [com.log4jtest.demo.logger.JpaLogEntity] does not extend AbstractLogEventWrapperEntity.
So, what can I do? I really wanna use this appender.
maybe you might do the following, I will appriciate it:
1. tell me how to extend my own class without the error ocured
2. maybe you have got some brilliant solution, pls share.
thanks in advance.

Related

UUID.randomUUID -> java.lang.StackOverflowError?

The title explains the problem I think, trying to create a random Id for an Object, I'm getting the following exception:
java.lang.StackOverflowError
at sun.security.provider.ByteArrayAccess.b2iBig64(ByteArrayAccess.java:274)
at sun.security.provider.SHA.implCompress(SHA.java:122)
at sun.security.provider.SHA.implDigest(SHA.java:103)
at sun.security.provider.DigestBase.engineDigest(DigestBase.java:186)
at sun.security.provider.DigestBase.engineDigest(DigestBase.java:165)
at java.security.MessageDigest$Delegate.engineDigest(MessageDigest.java:576)
at java.security.MessageDigest.digest(MessageDigest.java:353)
at sun.security.provider.SecureRandom.engineNextBytes(SecureRandom.java:226)
at java.security.SecureRandom.nextBytes(SecureRandom.java:455)
at java.util.UUID.randomUUID(UUID.java:145)
I don't think that anyone can tell me what is going on since I provide little information -> I know that.
The thing is: I have not any other information, I just create a randomUUID and it crashes.
So I'm just asking for ideas, since I don't find any googling this exception.
Thanks in advance.
EDIT:
Answer provided by
m0skit0 and scotth
Without noticing that the method which lead to an object creating a UUID was called nonstop I - well - did not notice that a huge amount of UUIDs was generated, which lead to the stackoverflow.
Thank you!

How to externalize error messages

This is a question of best practices for externalizing error messages.
I am working on a project where we have errors with codes, short descriptions and severity. I was wondering what the best way to externalize such descriptions is. What comes to my mind is to have them in code which is bad, to store them in database, to have them in property files, or maybe to have a static class loaded with descriptions. I think I will go with properties, but maybe there is a better way of doing it.
Thanks
Use a ResourceBundle to store those messages (and other user interface messages such as button and label text, accelerators, shortcuts, and so on). Here's a short example assuming that you have a bundle named ErrorMessages with an error named error.NameOfErrorMessage and a JFrame in the variable frame.
ResourceBundle errorMsg = ResourceBundle.getBundle("ErrorMessages");
String currError = errorMsg.getString("error.NameOfErrorMessage");
JOptionPane.showMessageDialog(frame, currError);
For more information you can see About the Resource Bundle Class in the internationalization tutorial.
We were faced with a similar issue. You are right that having the messages in the code is a poor choice. We found that a couple of factors influenced which alternative is better. In our case, we needed to have the same error codes handled in Java on the client side, and in SQL and Perl code on the server side. We found it useful to have a central definition so we used a data base.
If you only need to process the error codes in Java, a properties file or resource bundle is probably the most flexible, since they allow for localization and/or internationalization. I'd stay away from a static class; although it is better than in-line error descriptions, it is still relatively inflexible.
I suppose that there are some many ways to do this correctly.
The most common way I see is the use of external files that relates internal error codes in your actual code and a description something like
error.123="Error with data X"
warning.1="You must use ..."
To change the text error on your app you only need to change this text file. This is the way internationalization works
error.123="Error con el dato X"
warning.1="Deberías usar ..."

Java Netbeans error

I've been following the 'Netbeans E-Commerce tutorial', and have am currently on this step:
http://netbeans.org/kb/docs/javaee/ecommerce/entity-session.html
I have fully configured my Window 7 account as per that page, with NetBeans 6.9.1, Glassfish server and MySQL.
I'm getting an error 500 when executing 'Category' page (log extract below). The error manifests itself when I complete step 3 in the 'selected category' sub-section of the 'Accessing Data with EJBs' this page. The line in question is:
// get selected category
selectedCategory = categoryFacade.find(Short.parseShort(categoryId));
If I comment this line out, the bug goes away.
The log file snippet is here:
[#|2010-09-29T18:32:32.570+0100|WARNING|glassfish3.0.1|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=30;_ThreadName=http-thread-pool-8080-(2);|StandardWrapperValve[Controller]: PWC1406: Servlet.service() for servlet Controller threw exception
javax.ejb.EJBException
at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5119)
at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5017)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4805)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2004)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1955)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:198)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:84)
at $Proxy355.find(Unknown Source)
at session.__EJB31_Generated__CategoryFacade__Intf____Bean__.find(Unknown Source)
at controller.ControllerServlet.doGet(ControllerServlet.java:68)
Line 68 in the ControllerServlet code is the one identified above.
My experience with both Java and Netbeans is sufficiently light that I'm not even sure how to go about starting to debug this. I've followed the tutorial pretty closely, so it should not be something I've missed - but mistakes do happen.
I understand an outright solution based on the information contained would be difficult. If there is any further information required, please ask. Failing that, if anyone has any suggestions on how I can further investigate this on my own, I'd be very grateful.
I always think cracking problems is the best way to learn, but it is pretty frustrating as well.
Update:
I've been running through the NetBeans debugger. It appears that the problem is with the cast code (Short.parseShort(categoryId)). When I replace this with a simple numeral it works.
e.g. this code works
// get selected category
selectedCategory = categoryFacade.find(1);
Does anyone have any ideas why the cast is failing? categoryId is confirmed as a string with a value of "1" in the debugger...
Okay, I've cracked this. It was obviously my fault...
The table identity should have been set up as a short, instead I set it up as an integer. Therefore by casting the 'categoryId' string to short and passing it into the find method, I was passing in the wrong data type.
Replacing the 'Short.parseShort(categoryId)' argument with a 'Integer.parseInt(categoryId)' fixed the problem.
For those that took the time to read this; thank you.

Don't understand why I am getting this - 'Error: Value storage corrupted: negative offset'

I just started using IntelliJ-IDEA, and I don't know if the problem resides with the IDE or not. I'm assuming not but I have no idea. I've spent quite a lot of time googling this error to no avail.
The error comes about at compile time. The weird thing is that I returned my code to the way it was before the error was showing up and it is still being thrown. Here is a little bit of my code that I believe is causing the problem. But I think it might be something besides my code.
import org.joda.xpath.XPath;
private XPath componentXPath;
private List list;
this.componentXPath = XPath.newInstance("(//rss/channel/item)");
Document doc = jiraAdapter.fetch("path to XML file");
list = componentXPath.selectNodes(doc);
The componentXPath.selctNodes(doc) is somehow causing the problem. If i remove this line, then it compiles fine, but I need to get a list of all the nodes to work with.
The error shows up in the messages pane: Error: Value storage corrupted: negative offset
Any help would be greatly appreciated.
What IDEA version do you use? Try File | Invalidate Caches and then rebuild the project.

Please help, my program is not accepting MySQL floats

I have to use a java program . I need to understand it and then modify it. The program has a source folder. It has a lot of java files. the program has a GUI interface. i have imported the program in eclipse and i can run the program. i want to learn and understand the code but since its too big i want to only read the relevant portions of the code which i need to understand to modify / add features to the program. This program requires input data . this data can be in a CSV file or a MySql database. the immediate problem i am facing with the program is that i need to use float data as input data in one of the columns. when i put data in decimal form in the CSV file . the program has no problem in accepting it and processing it. but when i create a MYSQL database table with floating datatype as one of the column . the program while importing data gives error - "unknown data type float . add this entry is xxx.props file " even after i add the float entry in xxx.props file in the proper way just as other entries are there for other data types in xxx.props file, i still get the same error . what should i do next ? which part of the code should i study to find out the problem?
When you say it "gives error" - does it throw an exception? If so, find out where that exception is thrown from, and work backwards from there.
You haven't explained what the xxx.props file is, how you created the mysql table, or what you're then doing with it, which makes it kinda hard to give any more specific help...
Without a direct question, I can't help you much. However, I can advise you on how to solve the problem.
Learn the basics before you try to make a leap to do everything at once. Try to learn these before coming everything:
Get a working knowledge of Java
Figure out how to develop a GUI that isn't binded to your logic. (Take a look at the MVC design pattern)
Break up the big program into manageable parts
Implement your logic separately from your data access (M C part of MVC)
Use Unit Testing to verify that your components work
Implement the CSV reading, and then move it to the database
This way you have seperable components that will make your job easier to deal with, and you will learn quite a bit along the way.
You've got a lot of small questions but I think your main question is "why am I getting this 'unknown data type float' error". Without looking at any code my first suggestion would be to validate how you're inserting/updating the MySQL table. Hopefully the developer extrapolated the data tier from the UI tier meaning there should only be one or two java classes to look at to verify how the data is inserted.
Overall, it sounds like you're new to Java and application design. Try to follow how the program works from point A to point B. Hopefully the code was broken out into tiers to make it easier for you; IE the GUI is in it's own package/project and the business logic is in it's own package/project, so on and so on.

Categories

Resources