Programming Articles - Page 2310 of 3366

Difference between lazy and eager loading in Hibernate

Mahesh Parahar
Updated on 18-Nov-2019 06:20:10

16K+ Views

Lazy and Eager are two types of data loading strategies in ORMs such as hibernate and eclipse Link.  These data loading strategies we used when one entity class is having references to other Entities like Employee and Phone (phone in the employee). Lazy Loading − Associated data loads only when we explicitly call getter or size method.Use Lazy Loading when you are using one-to-many collections.Use Lazy Loading when you are sure that you are not using related entities. Egare Loading − Data loading happens at the time of their parent is fetched. Use Eager Loading when the relations are not too much. Thus, ... Read More

Difference between Save and SaveAndFlush in Spring Java

Teja Kolloju
Updated on 17-Apr-2025 18:59:54

6K+ Views

Save and SaveAndFlush both can be used for saving entities. They both are both belong to the Spring data library. Save may or may not write your changes to the DB straight away. When we call saveAndFlush system is enforcing the synchronization of your model state with the DB. What is the save method? The save method is used to store an entity in the database. It adds the entity to the transactional buffer, and when the transaction is committed, the data is saved. It then returns the stored entity. Example The following is an example of the save method ... Read More

Difference Between CrudRepository and JPARepository in Java

Teja Kolloju
Updated on 17-Apr-2025 18:59:05

23K+ Views

CrudRepository and JPA repository both are the interface of the spring data repository library. Spring data repository reduces the boilerplate code by providing some predefined finders to access the data layer for various persistence layers. What is JPA repository? JPA is a repository interface that extends CrudRepository and PagingAndSorting repository. It inherits some finders from crud repository such as findOne, gets and removes an entity. It also provides some extra methods related to JPA such as delete records in batch, flushing data directly to a database base and methods related to pagination and sorting. We need to extend this repository ... Read More

Importance of @JsonUnwrapped annotation using Jackson in Java?

raja
Updated on 09-Jul-2020 06:43:52

994 Views

The @JsonUnwrapped annotation can be used to unwrap values during the serialization and deserialization process. It helps to render the values of a composed class as if it belongs to the parent class.Syntax@Target(value={ANNOTATION_TYPE, FIELD, METHOD, PARAMETER}) @Retention(value=RUNTIME) public @interface JsonUnwrappedExampleimport com.fasterxml.jackson.annotation.JsonUnwrapped; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.core.JsonProcessingException; public class JsonUnwrappedAnnotationTest {    public static void main(String args[]) throws JsonProcessingException {       ObjectMapper mapper = new ObjectMapper();       String jsonString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(new Employee());       System.out.println(jsonString);    } } class Employee {    public int empId = 110;    public String empName = "Raja Ramesh";    @JsonUnwrapped   ... Read More

When to use @JsonValue annotation using Jackson in Java?

Manisha Chand
Updated on 19-May-2025 16:23:29

5K+ Views

In Java, Jackson is a library that is used to convert JSON to Java objects and vice versa. Jackson Annotations are used during serialization and deserialization. We use these to denote or specify annotations before a particular field or method (that is declared in Java). Using an annotation before a field, we can denote whether it is a variable, is a JsonProperty, should be ignored, or what condition should be applied to it. So basically, Annotations make JSON output clearer as we required. In this Article, we will learn about ... Read More

How to control serialization through @JSON annotation using flexjson in Java?

raja
Updated on 09-Jul-2020 06:17:06

300 Views

The @JSON annotation is used by JSONSerializer class to exclude or include a field during the serialization process. We can use the serialize() method of JSONSerializer class to perform a shallow serialization of the target instance.Syntax@Retention(value=RUNTIME) @Target(value={FIELD, TYPE, METHOD}) public @interface JSONExampleimport flexjson.JSONSerializer; import flexjson.JSON; public class JSONAnnotationTest {    public static void main(String[] args) {       JSONSerializer serializer = new JSONSerializer().prettyPrint(true);       Employee emp = new Employee("Raja", "Ramesh", 30, "Hyderabad");       String jsonStr = serializer.serialize(emp);       System.out.println(jsonStr);    } } // Employee class class Employee {    private String firstName, lastName, address;    private ... Read More

How to implement custom deserializer using @JsonDeserialize annotation in Java?

raja
Updated on 09-Jul-2020 06:19:40

3K+ Views

The @JsonDeserialize annotation is used to declare custom deserializer while deserializing JSON to Java object. We can implement a  custom deserializer by extending the StdDeserializer class with a generic type Employee and need to override the deserialize() method of StdDeserializer class.Syntax@Target(value={ANNOTATION_TYPE, METHOD, FIELD, TYPE, PARAMETER}) @Retention(value=RUNTIME) public @interface JsonDeserializeIn the below program, we can implement a custom deserializer using @JsonDeserialize annotationExampleimport java.io.*; import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.*; import com.fasterxml.jackson.databind.deser.std.*; public class JsonDeSerializeAnnotationTest {    public static void main (String[] args) throws JsonProcessingException, IOException {       Employee emp = new Employee(115, "Adithya");       ObjectMapper mapper = new ObjectMapper();     ... Read More

Uri.HexEscape(Char) Method in C#

AmitDiwan
Updated on 14-Nov-2019 06:57:07

171 Views

The Uri.HexEscape() method in C# is used to convert a specified character into its hexadecimal equivalent.SyntaxFollowing is the syntax −public static string HexEscape (char ch);Above, the parameter ch is the character to convert to hexadecimal representation.ExampleLet us now see an example to implement the Uri.HexEscape() method −using System; public class Demo {    public static void Main(){       char ch = 'k';       string res = Uri.HexEscape(ch);       Console.WriteLine("Hexadecimal Equivalent = "+res);    } }OutputThis will produce the following output −Hexadecimal Equivalent = %6BExampleLet us now see another example to implement the Uri.HexEscape() method ... Read More

UInt32.GetHashCode() Method in C# with Examples

AmitDiwan
Updated on 14-Nov-2019 06:56:00

128 Views

The UInt32.GetHashCode() method in C# is used to get the HashCode for the current UInt32 instance.SyntaxFollowing is the syntax −public override int GetHashCode ();ExampleLet us now see an example to implement the UInt32.GetHashCode() method −using System; public class Demo {    public static void Main(){       uint val1 = 100;       uint val2 = UInt16.MinValue;       Console.WriteLine("HashCode for val1 = "+val1.GetHashCode());       Console.WriteLine("HashCode for val2 = "+val2.GetHashCode());    } }OutputThis will produce the following output −HashCode for val1 = 100 HashCode for val2 = 0ExampleLet us now see another example to implement ... Read More

How to change the WindowWidth of the Console in C#?

AmitDiwan
Updated on 14-Nov-2019 06:53:59

139 Views

Use the Console.WindowWidth Property to change the WindowWidth of the Console.ExampleLet us now see an example −using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Demo {    public static void Main (string[] args) {       Console.InputEncoding = Encoding.ASCII;       Console.WriteLine("Input Encoding Scheme = "+Console.InputEncoding);       Console.OutputEncoding = Encoding.ASCII;       Console.WriteLine("Output Encoding Scheme = "+Console.OutputEncoding);       Console.CursorVisible = false;       Console.Write("Cursor is Visible? "+ Console.CursorVisible);       Console.WindowWidth = 30;       Console.Write("WindowWidth = "+Console.WindowWidth);    } } OutputThis will produce the following ... Read More

Advertisements