devxlogo

The Latest

How to use JPA, @MappedSuperclass

First, define an abstract class and annotate it with @MappedSuperclass. This is not an entity: @MappedSuperclasspublic abstract class User implements Serializable {   …} Second, each entity should extend the User class. For example, Student and Teacher entitites: @Entitypublic class Student extends User implements Serializable {   …} @Entitypublic class Teacher extends User implements Serializable {   …} Related Posts Beginner’s Guide to the Short PrimitiveGroundbreaking Drone Tech Disrupts Enemy CommunicationsCrypto ATMs Disappearing In London: What Does This Mean?Convert an Array of Strings

How to define an auto-incremented identifier via JPA annotations

For defining an auto-incremented identifier in an entity we need the @Id annotation and the IDENTITY generator as follows: @Entitypublic class User implements Serializable {     @Id    @GeneratedValue(strategy = GenerationType.IDENTITY)    private Long id;    …} Related Posts Renaming a User in MySQLtest 3 for white spacePlacer.ai raises $75M, boosts valuation to $1.5BJudge Blocks Treasury’s Shareholder Disclosure RuleReducing Unbuffered Streams

Read All SQL Server Log Files

You can use a script similar to the following to read through all SQL Server Log files: CREATE PROCEDURE SearchLogFiles (@LogType INT = 1, Filter NVARCHAR(MAX) = ”)ASBEGIN DECLARE @LogsTable

SQL Injection Part 3

lorum ipsum Related Posts Microsoft Releases .NET Core 1.0Summing a COUNT Aggregate SQL FunctionCrowdStrike and eSentire expand cybersecurity partnershipNew CRAM hardware slashes AI energy useUnderstanding the Java.time Package

Employing DROP USER in MySQL

As with any database, MySQL provides powerful user management feature. Learn how to remove a user from the database. DROP USER SRIDHAR However, the catch here is that the user

Finding the Current Flush Mode for the JPA EntityManager

Knowing the current flush mode can be done as follows: // via EntityManagerentityManager.getFlushMode();// in Hibernate JPA, via Session(entityManager.unwrap(Session.class)).getFlushMode();// starting with Hibernate 5.2(entityManager.unwrap(Session.class)).getHibernateFlushMode(); Related Posts Activate Hibernate Second Level Cache for

AngularJs ??? perform ng-click on a condition

Add the check along with the function call as below.  Admin Function  Related Posts Generation of Equivalent Binary Code of Decimal DigitsHow to Check if a List is Empty in PythonEsa scientists 3D print space bricksCreate Quick Documentation for your

Find if a string contains one of the given words in Java

We can use the AnyMatch method to figure out if a string contains any of the given words from an Array. See below for a sample.  List middleEasternCountries = Arrays.asList(“egypt”, “iran”, “turkey”);String sampleString = “Egypt is a famous tourist destination. It contains the Pyramids”; System.out.println(middleEasternCountries.stream().anyMatch(sampleString::contains)); Related Posts MGDrawVis: Revolutionizing Graph VisualizationCOBOL at 65: still a powerhouse in the tech industryTips for Unit Testing with MocksGenerating Gray Codes in CAcer Aspire 1 ARM:

Retrieving remainder of two numbers in Python

Using Math module, we can retrieve the remainder of two numbers For e.g. the following would return 0.import math re = math.remainder(6, 3)) Related Posts Disrupting Electronics with 2D SemiconductorsHybrid Integrations with Azure Logic AppsDatabricks Adds Deep Learning and GPU Acceleration to SparkTech Layoffs Are Getting Worse GloballyHow to Become a

Transpose a Matrix in Python

One of the inbuilt libraries in Python is zip. It can be utilized to transpose a matrix by performing an Unzip followed by zip. Sample code below.   Python comes with many inbuilt libraries zip is among those. The??zip()??function returns an iterator of tuples based on the??iterable??object. In order to get the transpose of the matrix first, we need to unzip the list using??*??operator then zip it. inputMatrix = [ [7, 14, 21], [1, 2, 3] ]zip(*inputMatrix) Output will be as follows:[ (7, 1), (14, 2), (21, 3) ]  Related Posts How To Delete Apps On AndroidThrilling APEC Summit 2023 Showdown2015’s Top Jobs Include Mobile Development, Cloud EngineeringAuthenticate RESTful APIs with an OAuth ProviderGet the

Creating a Secure Socket

Java supports creating of ServerSocket(s) in more than one way. This is an important aspect of security. SSLServerSocketFactory is a secure way of achieving this. This ensures that the socket is

Replace a Web API Response with a Custom JSON

Use StringContent?in the Web API response to return a custom JSON. See below for an example: StringContent responseContent = new StringContent ( ” { ‘handled’ : ‘true’ } “, Encoding.UTF8,

How to Disable Auto-commit Mode in Spring Boot

By default, Spring Boot uses HikariCP as the connection pool. Via the connection pool, we can disable the auto-commit mode. For example, the following setting disabled auto-commit mode from application.properties:

Understanding INSERT IGNORE in MySQL

Usually, if there is an error during the INSERT command execution, the error is thrown and the execution stopped. MySQL supports something named IGNORE along with INSERT, which captures the

How to Use FetchMode.JOIN to Fetch Collection

By annotating an associated collection with FetchMode.JOIN we force it to be loaded EAGER: @OneToMany(fetch = FetchType.LAZY)@Fetch(FetchMode.JOIN)private List = new ArrayList(); Or: @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = “foo_id”) @Fetch(FetchMode.JOIN) private

Using the STRING_AGG SQL Server 2017 Function

The STRING_AGG?SQL Server 2017 function performs grouped string concatenation. Here is an example: SELECT STRING_AGG(value, ‘ ‘) AS Result FROM (VALUES(‘Hannes’),(‘du’),(‘Preez’)) AS I(value); This returns: Hannes du Preez in the

How is HeapHero different?

 There are excellent Heap dump analysis tools like Eclipse MAT, Jprofiler, … These tools are handy when you want to debug/troubleshoot OutOfMemoryError. However, we HeapHero as following unique capabilities which aren’t available in those tools:  1. How much memory wasted?    HeapHero tells you how much memory your application is wasting because of inefficient programming practices by the developers. Today memory is wasted because of reasons like: a. Duplication of stringsb. overallocation, and underutilization of data structuresc. Boxed numbersd. Several more reasons.  You can see HeapHereo reporting how much memory is wasted even in a vanilla pet clinic spring boot application. Other tools don’t provide this vital metric.  2. First cloud application for heap dump analysis  Today’s memory profiling tools need to be installed on your Desktop/Laptops. They can’t run on the cloud. HeapHero can run on  a. Public cloud (AWS, Azure,..)b. Your private data centerc. Local machine Your entire organization can install one instance of HeapHero in a central server, and everyone in the organization can upload and analyze the heap dump from this one server.  3. CI/CD pipeline Integration   As part of CI/CD pipeline, several organizations do static code analysis using tools like coverity, vera code… . Using HeapHero, you can do runtime code analysis. HeapHeroprovides REST API. This API returns JSON response, which contains key metrics related to your application’s memory utilization. You can invoke this API from CI/CD pipeline and see whether your code quality is improving or regressing between each code commit.  4. Instant RCA in production  Debugging OutOfMemoryError in production is a tedious/challenging exercise. You can automate the end-end analysis of OutOfMemoryError using HeapHero. Say if your application’s memory consumption goes beyond certain limits or experience OutOfMemoryError, you can capture heap dumps and do heap dump analysis instantly using our REST API and generate instant root cause analysis report. Production troubleshooting tools like ycrash leverages HeapHero REST API to do this analysis for you.  5. Analyzing heap dumps from remote location  Heap dump files are large in size (several GB). To troubleshoot the heap dump, you have to transmit the heap dump file from your production server to your local machine. From your local machine, you have to upload the heap dump file to your tool. Sometimes heap dump might be stored/archived in remote server, AWS S3 storage,… In those circumstances, you will have to download the heap dump from that remote location and then once again upload it to the tool. HeapHero simplifies this process for you. You can pass the heap dump’s remote location URL as input to the HeapHero API or to web interface  directly. HeapHero will download the heap dump from this remote location to analyze for you.  6. Report Sharing & Team collaboration  Sharing Heap Dumps amongst team is a cumbersome process. Finding a proper location to store the heap dump file is the first challenge. The team member with whom you are sharing this report should have the heap dump analysis tool installed on his local machine. So that he can open the heap dump file with the tool you are sharing to see the analysis report. HeapHero simplifies this process. HeapHero gives you a hyperlink like this. This hyperlink can be embedded in your emails, JIRA, and circulated amongst your team. When your team member clicks on this hyperlink, he can see the entire heap dump analysis report on his browser.  HeapHero also lets you export you heap dump as PDF file. This PDF file can also be circulated amongst your team members. 7. Analyze large size heap dumps  Several memory profilers are good at analyzing heap dumps of smaller size. But they struggle to analyze large size heap dumps. HeapHero is geared to analyze heap dumps easily.  Author bioEvery single day, millions & millions of people in North America???bank, travel, and commerce???use the applications that Ram Lakshmanan has architected. Ram is an acclaimed speaker in major conferences on scalability, availability, and performance topics. Recently, he has founded a startup, which specializes in troubleshooting performance problems. Related Posts Shortcut to create a new page/move content

Using REPEAT in MySQL

MySQL provides a REPEAT command that can be used when you want to repeat a particular string, a defined number of times. Consider the example below: SELECT CONCAT(‘S’,REPEAT(“E”,2)) Here, we

How to Cache Query Results

If em is the EntityManager, then the following query results will be cached: Query query = em .createQuery(“SELECT u FROM User u”); query.setHint(“eclipselink.cache-usage”, “CheckCacheThenDatabase”); Related Posts California Senate approves AB

Understanding UNCOMPRESSED_LENGTH in MySQL

In MySQL, once we use the COMPRESS method to compress a particular text, the LENGTH of the resultant text is not the same as that of the original text. However,

Date Settings Problem (Regional Settings)

Regional Settings, especially dates, are always a problem in code. For example, suppose your product is developed in the U.S. and deployed in the UK. DateTime.Parse would throw exceptions because String

Tip: Regional Date Settings Problems

Regional Settings, especially dates, are always a problem in code. For example, suppose your product is developed in the U.S. and deployed in the UK. DateTime.Parse?would throw exceptions because String

SQL Statistic Tests to Look Into

If you want to do statistics in SQL, the following tests will be very useful to look into: Pearson’s Correlation Kendall’s Tau Rank Correlation Simple Linear Regressions The Kruskal-Wallis Test

How to Set hibernate.format_sql in a Spring Boot Application

For formatting the SQL statements in a Spring Boot application, we can set hibernate.format_sql in the application.properties as follows: spring.jpa.properties.hibernate.format_sql= true Related Posts Shield AI expands autonomous flight software to

Understanding sql_mode in MySQL

In MySQL, the sql_mode can have values set, so that the behaviour of the SQL being executed henceforth behaves as per the mode set. Considering the following use case where

How to Call a Macro Every “n” Minutes

We write a lot of macros to automate many of our mundane repeated tasks. Taking it to the next level, we can call the macro in a pre-determined frequency and

How to Join (Combine) Fix File Paths

In order to join (combine) fix file paths we can use Path#resolve() and Path#resolveSibling():. // using Path#resolve()Path base1 = Paths.get(“D:/learning/books”); Path path1 = base1.resolve(“Java.pdf”);// using Path#resolveSibling()Path base2 = Paths.get(“D:/learning/books/Java.pdf”);Path path3

Shortcut to Zoom in Chrome

It’s easy to use shortcuts to zoom in Chrome. Just press the ctrl key and just scroll your mouse middle button up to zoom in and button down to zoom

Extract Digits from a String in Python

See how to extract digits from a string in Python using a regular expression. import reinputString = ‘QuinStreet2019Year’result = re.sub(“D”, “”, inputString) Related Posts Smart watch alerts woman to heart

How to Sort a Collection

An approach for sorting a Java collection can rely on Collections.sort() method as in the following example: List names = new ArrayList(); names.add(“John”); names.add(“Alicia”); names.add(“Tom”); Collections.sort(names); // sort ascending by