spring JDBC bean property maaping with oracle object attribute - spring-jdbc

I have trouble to mapping oracle object attribute with its equivalent sprig bean property.
Example:
create or replace type typ_test is object(attr1 number,attr2 varchar(20));
Spring bean:
class Person{
private Integer sno;
private String sname;
//Getters and Setters
}
Now I want to map the oracle object type attribute with Spring bean object (Person).

Related

How to prove JPA Enity must not be final class with Hibernate 5

JSR 338: JavaTM Persistence API 2.1 Specification > 2.1 The Entity Class specifies:
The entity class must not be final. No methods or persistent instance variables of the entity class may be final.
So I tried with Hibernate 5.2.18.Final to prove it by setting an entity class as final:
#EqualsAndHashCode
#Getter
#Setter
#Entity
public final class City {
#Id
#SequenceGenerator(name="city_sequence", sequenceName="city_seq", initialValue=0, allocationSize=25)
#GeneratedValue(strategy=SEQUENCE, generator="city_sequence")
private int id;
#Column(length=20, nullable=false)
private String city;
#ManyToOne(fetch = FetchType.LAZY)
private Province province;
}
However, the result is out of my expectation: the corresponding table can be generated and new instance of City can be persisted to the database, meaning my code proves that entity class can be final
Question: Is there any better way to prove the entity class must not be final? Isn't it a hard-and-fast rule as it is in the specification?

Spring MVC why my property is null when invoke an #Value property

My code as following:
public class BgpService{
#Value("${serviceName}")
private String serviceName;
private String fullName = serviceName+"/rest"
}
I do have serviceName in my config.properties file, the value is serviceName=10.1.1.1, But when I use fullName the value is null/rest, I expected it should be 10.1.1.1/rest.
Couple of things you need to check & fix in your code.
From your given snippet you are missing the #Component & #Configuration & #PropertySource annotation
#Component
#Configuration
#PropertySource("classpath:config.properties")
public class BgpService{}
You are trying to assign/use the value of serviceName field on static level (class) hence you need to define the field serviceName as static.
#Value("${serviceName}")
private static String serviceName;
And add a post construct method in order to assign value to another field. Currently your initialisation is invalid.
#PostConstruct
public void init(){
fullName = serviceName+"/rest"
}
Is your class "BgpService" considered as a spring bean? Do you have any spring annotation above it (e.g. #Service or #Component)? Is this class within the "component scan" range? Properties are injected by Spring to Spring beans only.
Can you access other properties from your config file from another class? This will show if your property file is within a classpath.

How to inject DAO bean in tapestry (with Spring JDBC)

I am using Spring-JDBC with Tapestry and not able to inject DAO bean which I have defined in Spring.xml. Normally we use applicationContext.getBean, but in tapestry I am not able to find such option. Please guide me how I can inject DAO bean to use it in my code. Below is kind of code I am having:
Class ABC{
with private members, getters,setters and constructors
}
Class abcDAO{
private JdbcTemplate template
//getter and setter for jdbc template
//a method which will extract data using Rowmapper
public Set<ABC> getAll(){
//override mapRow method
}
}
I want to use getAll method in a class which will process extracted data. Please help me where should I inject abcDAO bean with below line:
#Inject private abcDAO abcDao;
Thanks in advance!!!

Wcf ria services - custom objects with EF entities - can't compile

I have custom entity (not from entity model), which have a property, wich return collection of EF entities (from entity model):
[DataContract]
public class MyEntity
{
[DataMember]
public List<Role> Roles { get; set; }
}
The 'Role' and 'RolePermission' entities are generated by EF4 from DB.
RolePermission has FOREGIN_KEY to Role, and EF4 was generated association between Role and RolePermission:
Role.RolePermissions --navigate property
RolePermission.Role --navigate property
Also, I have DomainService:
[EnableClientAccess()]
public class MyEntityService : DomainService
{
public List<MyEntity> GetMyEntities()
{
...
myEntityInstance.Roles = <GetRoles>
...
return <collection of MyEntities with Roles>
}
}
When I try to compile this, I get error:
Entity 'UserManager.Web.RolePermission' has a property 'RoleReference' with an unsupported type
When I put [Include] attribute to MyEntity.Roles property, I get the same error and this error:
Property 'Roles' of complex type 'MyEntity' is invalid. Complex types cannot have include members.
when I removed reference from RolePermission to Role (RolePermission.Role navigate property) by hands (from entity model), I get only this error in compile time:
The Entity 'Role' in DomainService 'RolesService' does not have a key defined. Entity types exposed by DomainService operations must have at least one public property marked with the KeyAttribute.
How can I resolve this situation? How can I return my custom object (MyEntity) with filled Roles property from MyEntityService?
A added [key] attr to Role.Metadata, and compile succesfull. But there are no MyEntity.Roles property on the client.
RIA services requires all objects passed back and forth between client to server to have a unique key so it knows which specific object you are modifying.
If you must have your own object as a wrapper for EF objects, just add an id member marked with [key] and maintain that value yourself.
[DataContract]
public class MyEntity
{
[key]
public int Id { get; set; }
[DataMember]
public List<Role> Roles { get; set; }
}
There seems to be something wrong with the design if you need to do that. What is the parent of a group of roles in your application? Why not just query roles?

Spring 3 - Stop serializing an autowired bean

I have a session object which contains a reference to another object that I do not wish to serialize.
Is it possible to do so using annotations?
#Component
public class Model implements Serializable{
private static final long serialVersionUID = 1L;
#Autowired
private Validator validator;
Thanks in advance,
You can mark it with transient, though it would be null after deserialization.
You can also move the validation out of the POJO into a helper class. You could use the validation annotations from javax.validation describe in JSR-303. Here is a howto link:
http://www.openscope.net/2010/02/08/spring-mvc-3-0-and-jsr-303-aka-javax-validation/

Resources