Spring org.springframework.beans.ConversionNotSupportedException exception - java

Could someone say why I am getting this exception ?
And how to solve the problem ?
If I understand correctly com.test.dao.CustomerDAO$$EnhancerByCGLIB$$ae49026e_3 class generated at runtime by spring.
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.test.dao.CustomerDAO$$EnhancerByCGLIB$$ae49026e_3' to required type 'com.test.dao.CustomerDAO'

Related

Inject #Value to a Path variable directly

I want to inject Path variable directly without converting it from string like this:
#Value("${screenshot.path}")
private Path path;
property file:
screenshot.path=D:\Projects\myproject\screenshots
Error:
Unsatisfied dependency expressed through field 'path'; nested
exception is org.springframework.beans.TypeMismatchException: Failed
to convert value of type 'java.lang.String' to required type
'java.nio.file.Path'; nested exception is
java.lang.IllegalArgumentException: Failed to retrieve file for class
path resource [D:/Projects/myproject/screenshots]
Is there a way to do that without injecting String and then doing Paths.get?
My mistake, it does everything automatically, just fixed path format like this:
screenshot.path=D:\\Projects\\myproject\\screenshots

Spring 3.2.4 can't convert String to Enum in <util:map.../> although 'key-type' is specified

I'm trying to define a map bean with Spring 3.2.4 with an Enum as the key type, this way:
<util:map id="myMapping" key-type="com.acme.MyEnum">
<entry key="ENUM1" value="value1" />
<entry key="ENUM2" value="value2" />
</util:map>
The MyEnum class is a trivial class:
public enum MyEnum
{
ENUM1,
ENUM2
}
When creating the application context, Spring throws this exception:
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'myMapping':
Error converting typed String value for bean property 'sourceMap';
nested exception is org.springframework.beans.ConversionNotSupportedException:
Failed to convert value of type 'java.lang.String' to required type
'com.acme.MyEnum'; nested exception is java.lang.IllegalStateException:
Cannot convert value of type [java.lang.String] to required type
[com.acme.MyEnum]: no matching editors or conversion strategy found
(formatted for better readbility)
I expected Spring to convert the String "ENUM1" to "MyEmum.ENUM1", because of the given key type
key-type="com.acme.MyEnum"
in the mapping bean declaration.
I know how to solve this by doing an alternate bean definition, using <entry>, using the full qualified class name of the enum etc... But I would like to build the defintion as described for easy readability.
Is this a known bug or a lack of understanding on my side?
Thanks a lot for your help!
You could try to use this strategy for string conversion.
public enum MyEnum
{
ENUM1("ENUM1"),
ENUM2("ENUM2")
}
Actually it seems correct how do you use utils-map, but may be the problem is elsewhere.
I don't know how do you inject the created myMapping bean. If you use #Autowired, it is a possible reason why you get this exception. You should use #Resource(name="myMapping") instead of #Autowired. See this ticket.
I have already test it and it works. If you want to see how, I created a sample project and pushed on github. Follow this link.
I hope it helps.

netbeans, EJB, glassfish, e-commerce tutorial issues

I’ve been following the e-commerce tutorial located here: http://netbeans.org/kb/docs/javaee/ecommerce/intro.html
Code repo of project here.
I have ran into a few problems that I believe are related:
1: Trying to view the customers’ orders on the Admin page results in:
**WARNING**: EJB5184:A system exception occurred during an invocation on EJB OrderManager, method: public java.util.Map session.OrderManager.getOrderDetails(int)
**WARNING**: javax.ejb.EJBTransactionRolledbackException
**WARNING**: EJB5184:A system exception occurred during an invocation on EJB OrderedproductFacade, method: public java.util.List session.OrderedproductFacade.findByOrderId(java.lang.Object)
**WARNING**: javax.ejb.TransactionRolledbackLocalException: Exception thrown from bean
Caused by: java.lang.IllegalArgumentException: You have attempted to set a parameter value using a name of customerOrderId that does not exist in the query string SELECT o FROM Orderedproduct o WHERE o.orderedproductPK.custOrderid = :custOrderid.
2: Trying to view details for a particular order in the admin page results in:
WARNING: StandardWrapperValve[AdminServlet]: PWC1406: Servlet.service() for servlet AdminServlet threw exception
Caused by: java.lang.IllegalArgumentException: You have attempted to set a parameter value using a name of customerOrderId that does not exist in the query string SELECT o FROM Orderedproduct o WHERE o.orderedproductPK.custOrderid = :custOrderid.
Both problems have the ‘findByOrderId’ method in common and I am at a loss as to what is wrong with it.
The offending method is located in the following directory: src/jsf_crud/src/java/session/OrderedProductFacade.java
(I would link it as a hyperlink but spam prevention measures prevent me)
Not sure what the best course of action is, any recommendations?
Your query needs a parameter called "custOrderid" and not "customerOrderId"
Either change the query or change the called parameter.
The query in the OrderedProduct class uses "customerOrderId"
http://netbeans.org/projects/samples/sources/samples-source-code/content/samples/javaee/AffableBean/src/java/entity/OrderedProduct.java

Java: how to make sense out of cryptic stack traces?

While trying to run a unit test, I get the following stack trace. I don't even know where to start looking (read my comment below).
Where should I start and what would you do to solve this?
(note that the following stack trace is basically how I get it from Eclipse, without any formatting or anything: just countless lines of about 120 chars each) [I only pasted the five lines where apparently the problem happens]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'acceptanceChain' defined in class path resource
[.../chain/connector/...xml]: Cannot resolve reference to bean 'xxxCommand' while setting constructor argument with key [0]; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xxxCommand' defined in class path resource
[.../bl/chain/connector/....xml]: Cannot create inner bean 'yyyDTO#1d95da7' of type [yyyListDTO] while setting bean property 'yyyListDTO'; nested exception
is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'yyyListDTO#1d95da7' defined in class path resource
[zzz.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [boolean]: Could not convert constructor argument value of type
[java.util.LinkedHashMap] to required type [boolean]: Failed to convert value of type [java.util.LinkedHashMap] to required type [boolean]; nested exception
is java.lang.IllegalArgumentException: Cannot convert value of type [java.util.LinkedHashMap] to required type [boolean]: no matching editors or conversion
strategy found
Any help is very welcome.
Take the signifiant part of the message :
Error creating bean with name 'acceptanceChain' defined in class path resource
I guess the bean acceptanceChain can't be instanciated. Maybe because it has a boolean parameter in which one tries to inject a LinkedHashMap, as the following message states :
Failed to convert value of type [java.util.LinkedHashMap] to required type [boolean]

Marshalling argument exception

The server starts fine, but the error occurs
when I try to add any job from the Client.I get the
following error
java.rmi.MarshalException: error marshalling arguments; nested exception
is:
java.io.NotSerializableException: snaq.db.CacheConnection
at Production_Stub.addGRN(Production_Stub.java:1515)
at ProductionServices.addGRN(ProductionServices.java:21)
at PlanningServices.addGRN(PlanningServices.java:22)
at Planning.addtoGrn(Planning.java:9949)
at Planning.saveAllBundleRelatedTables(Planning.java:9582)
at Planning.savebundlesheet(Planning.java:9251)
at Planning_Skel.dispatch(Planning_Skel.java:6555)
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:342)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:207)
at sun.rmi.transport.Transport$1.run(Transport.java:148)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:534)
Caused by: java.io.NotSerializableException: snaq.db.CacheConnection
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1059)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
at Production_Stub.addGRN(Production_Stub.java:1513)
... 14 more
Pls give me the solution..
What is going on here is that one of the object that you are trying to send over RMI is an instance of the class snaq.db.CacheConnection, or (more likely) contains a reference to one somewhere.
This ain't going to work. The CacheConnection class is not serializable, and there's a good chance that cannot be made serializable.
A possible cure for this is to mark the field (or fields) of type CacheConnection in the classes you are trying to send as transient.

Categories