I’ve got following classes: When I serialize Container class using Jackson I get But I need the result to be: Is it possible (without adding Container.getDataId() method)? If so, how to do it? update I’ve tried to create custom JsonSerializer<Data> but the result was same as before I’ve also tried to add @JsonSerialize annotation above Data class, then above getter
Tag: spring
An alternative to @Value annotation in static function
It’s not possible to use @Value on a static variable. When I do this, 0 is printed. So what is a good alternative to this? Answer Spring inject noting in static field (by default). So you have two alternatives: (the better one) make the field non static (the ugly hack) add an none static setter which writes in the static
Java / Hibernate – Write operations are not allowed in read-only mode
I’ve been having an annoying exception a lot lately, and after some research on Google and this forum I still haven’t found an answer that could solve my problem. Here’s the thing – sometimes, I get the following error when trying to update or create a new object with hibernate: What is really strange is that, sometimes when updating an
Implement a simple factory pattern with Spring 3 annotations
I was wondering how I could implement the simple factory pattern with Spring 3 annotations. I saw in the documentation that you can create beans that call the factory class and run a factory method. I was wondering if this was possible using annotations only. I have a controller that currently calls MyService is an interface with one method called
How to use object oriented programming with Hibernate?
While using ORM tools such as Hibernate, I’ve found it is advantageous to keep all business logic out of my business objects and instead keep it in a service layer. The service layer creates the business object POJOs, manipulates them, and uses DAOs to save them. But isn’t this in a way taking a step backwards from the object oriented
when is a spring bean instantiated
In the above, when are the beans instantiated, when the ApplicationContext is created or when the getBean() is called? Answer Assuming the bean is a singleton, and isn’t configured for lazy initialisation, then it’s created when the context is started up. getBean() just fishes it out. Lazy-init beans will only be initialised when first referenced, but this is not the
How does dependency injection work in Spring?
I want to know how spring does dependency injection. I want the low level logic used. Updates: I want to know how the object references are injected to the constructors or setter methods, is it …
How do I retrieve default validation messages from Hibernate Validator?
I’m trying to retrieve a default validation error-message using MessageSource. The code I’m working with uses reflection to retrieve the value of the message parameter. On a constraint that does not override the message parameter, I would like to retrieve the default error message. When I invoke the message method on the validation annotation, I get {org.hibernate.validator.constraints.NotBlank.message} (for example, for
How to monitor slow SQL queries executed by JPA and Hibernate
Is there any Hibernate property I could set to see all the slow queries? I’, interested in queries that take too much time to return the result set. I’m using Spring with Hibernate, configured via an applicationContext.xml Spring configuration file. Answer I have 2 suggestions: you could use Oracle’s Statspack. you could use some kind of JDBC proxy driver logging
“unable to locate Spring NamespaceHandler” error
I’m creating a stand-alone Sava application with Spring, to handle the JDBC access. The application works fine on every test and I decided that I need a jar to be deployed our clients. They might not have spring in their classpath, so I used maven-assembly-plugin to handle the jar creation with dependencies. However when I try to run the application: