How can you order your mind?

We are taught from a very young age that regular exercise and nutrient-dense foods are the recipe for a long and healthy life. What we are often not taught is how our overall health, well-being, and behaviors are deeply impacted by our ability to observe our mind and our thoughts. In this entry, I will share information with you about the power of your thoughts and some simple steps for you to begin observing your mind.

As a highly sensitive person, I am not someone that reads the news with any regularity. When I do, the outcome is normally deep lingering thoughts and emotions that have a tendency to impact me for a long period of time. I don’t love the fact that I can sometimes feel “out of the loop” or not “up to date” on current affairs, but I have found that not following the news keeps me feeling more grounded and aware of my current reality. However, every once in awhile there is a monumental worldwide event that feels impossible to ignore and important to explore.

Reading about the massacre in Orlando left me jaw-dropped and bleary-eyed, each tear expressing a wide myriad of emotion. As I dove off the deep end into the articles, images, and social media opinions of the horrific attack, I noticed the immensity of overwhelming thoughts both enter and exit my mind. Closing my eyes, I began to observe the frantic, intense nature of these thoughts and how they began impacting my feelings and physical body. My chest felt tight and hot, my heart felt closed, and my head started to pound.

Mindfulness is defined as moment-to-moment awareness, without judgment. The first of three Mindful pillar, presence, is the practice of being in the now, becoming aware of our thoughts and creating space between these thoughts and our reaction(s) to them. These practices are well researched and scientific studies have proven over and over again that practicing mindful awareness, or simply observing our minds, has a powerful impact on our overall health.

One of the earliest studies on mindfulness and how it affects the brain and the immune system was led by Richard Davidson, Ph.D., in 2003 at the University of Wisconsin–Madison. The study looked at how an eight-week mindfulness-based stress reduction course led by Jon Kabat-Zinn altered the brain and immune cells of the participants.

The participants of both the experiment group and control group were asked to assess how they felt throughout the course of study in addition to having the electrical activity in the prefrontal cortex of the brain (an area specialized for certain kinds of emotion) measured. What the researchers uncovered was twofold:

  • The experiment group showed increased activation in the prefrontal cortex (therefore reducing anxiety and increasing positive emotional states), whereas the control group did not.
  • Immediately after the eight weeks, both the experiment and control group were administered flu vaccinations. Four weeks later, researchers tested for flu antibodies in both groups and found that the individuals implementing a meditation practice after the course had far more antibodies than the participants of the control group.

Want to really drop your jaw? Check out the remarkable study conducted at UCLA that vividly demonstrates how a similar eight-week course helped to slow the progression of HIV for people with the disease.

Reading through these experiments I can’t help but think of the following quote by Leon Brown:

“It all begins and ends in the mind. What you give power to has power over you.”

When we begin the process of observing our minds and separating ourselves from our thoughts and feelings (more on this topic next week), we are able to clearly see that we are not our thoughts or our feelings. Rather, our experience becomes whatever we become attached to: the endless chatter and dramatic saga that we’ve made up in our minds or the reality of the present moment.

Here are my seven simple steps to observing your mind:

  1. Close Your Eyes: It’s important to remove external distractions so you can truly become aware of what is happening inside.
  2. Take Five Deep Breaths: Breathing allows you to become grounded and gain clarity.
  3. Notice Your Thoughts: What thoughts come in and what thoughts go out?
  4. Observe Your Brain Chatter: Notice the frequency, rhythm, and pattern of your thoughts.
  5. Let Go of Self-Identification: Thoughts come and thoughts go. Imagine that your thoughts are like leaves falling onto a moving river. How are you identifying with your thoughts and allowing them to impact your sense of self and well-being?
  6. Take Five More Deep Breaths: Trust me, it won’t hurt.
  7. Notice That You Are Still Not Your Thoughts!

When I walk myself through these steps, the enormity of such tragic news doesn’t disappear, but my desire to be reactive in my approach to handling the information softens. This softness that comes from observing the mind allows for opportunities individually and universally to change, connect, grow, and heal. This softness has the ability transform hate, prejudice, racism, fear, sexism, stress, and anxiety into love.

And the world certainly needs all the love it can get.

Message from the Editor:

If you are looking for more opportunity to explore the topics mentioned in this article, come to our free and open-to-all Mindfulness Community event June 23rd here in San Francisco.

 

reference : http://www.mindfulorderofbeing.org/7-steps-observing-mind/

Advertisements

Difference between LAZY and EAGER fetching strategies.

Lets say that we have a Department and an Employee relationship in our data model. The department could have attributes such as, an id, a name, a description, and a collection of employees that belong to that department. This will be a one-to-many relationship from the Department’s view (a department can have many employees), and a many-to-one from the Employee’s.  Lets, illustrate this with the following example.

@Entity

public class Department {
        @Id
private Long id;
private String name;
private String description;
        @OneToMany(mappedBy = “department”)
private List<Employee> employees;
       ….
       public List<Employee> getEmployees() {
          return empoloyees;
       }
      ….
}
@Entity
public class Employee {
        @Id
private Long id;
private String firstName;
private String lastName;
@ManyToOne()
@JoinColumn(name = “employee_id”)
private Department deparment;
       …
}
Now, if we need to load (fetch) a department from the database, Hibernate/JPA could load these properties in two different ways: Lazy and Eager. Lazy loading practically means that Hibernate/JPA will only load the id, name and description, but  if we need to load the employees, we’ll request them on-demand by using the getEmployees() assessor method of the Department’s class. If the department has many employees, then it might not be very efficient to load all of them when they are not needed. To specified Lazy loading  we’ll modified our OneToMany annotation as follows.
@OneToMany( fetch = FetchType.LAZY)
With Eager loading, Hibernate/JPA loads all the properties’s data along with all the employees associated with a department. To specified Eager loading  we’ll modified our OneToMany annotation as follows.
@OneToMany( fetch = FetchType.EAGER)
Note:  The default fetching strategies:
EAGER: @OneToOne, @ManyToOne.
LAZY: @OneToMany, @ManyToMany

$ is not defined

It could be that you have your script tag called before the jquery script is called.

 type="text/javascript" src="js/script.js">

 src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript">

This results as $ is not defined

Put the jquery.js before your script tag and it will work 😉 like so:

 src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript">

 type="text/javascript" src="js/script.js">

JPA @OneToMany and @ManyToOne Unidirectional and Bidirectional

Hello, good morning.

Let us see today about @OneToMany and @ManyToMany Unidirectional and Bidirectional relationship.

We can use the @OneToMany relationship with two annotations: @JoinColumn or @JoinTable.

I will use a simple user case, a Customer can have many dogs but a Dog can have only a Customer.

The Dog class:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package com;
//Using the * to make the import list smaller
import javax.persistence.*;
@Entity
@Table(name="DOG")
@SequenceGenerator(name="DOG_SEQUENCE", sequenceName="DOG_SEQUENCE", allocationSize=1, initialValue=0)
public class Dog {
    public Dog(){
    }
    public Dog(String name){
        this.name = name;
    }
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="DOG_SEQUENCE")
    private int id;
    @Column
    private String name;
    //Getters and Setters
}

Notice that our Dog code is Unidirectional, it does not refer to the Customer class.

First we will see the Customer class with the @JoinTable annotation:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com;
import java.util.List;
//Using the * to make the import list smaller
import javax.persistence.*;
@Entity
@Table(name = "CUSTOMER")
@SequenceGenerator(name = "CUSTOMER_SEQUENCE", sequenceName = "CUSTOMER_SEQUENCE", allocationSize = 1, initialValue = 0)
public class Customer {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "CUSTOMER_SEQUENCE")
    private int id;
    @Column
    private String name;
    @OneToOne(cascade = CascadeType.ALL, optional = true, fetch = FetchType.EAGER, orphanRemoval = true)
    @JoinColumn(name="USER_ID", nullable=true)
    private User user;
    @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
    @JoinTable(name="CUSTOMER_HAS_DOGS", joinColumns={@JoinColumn(name="CUSTOMER_ID", referencedColumnName="id")}, inverseJoinColumns={@JoinColumn(name="DOG_ID", referencedColumnName="id")})
    private List dogs;
    //Getters and Setters
}

The @JoinTable annotation is simple and easy to use:

  • “name” – indicates which table will do the “join” between the Dog and the Customer (It is a good practice to put in the table name: owner + dependent side).
  • “joinColumns” – “let the JPA know” through an array of keys that will identify a record. It could be, e.g., ID and the name columns.
  • “@JoinColumn” – indicates a column to be the primary key of the owning side in the relationship. “name” is the column name and the “referencedColumnName” is the primary key of the related class; in this relationship the owner is the Customer class. (In the end of this post we will see who the real owner of this relationship is).
  • “inverseJoinColumns” – defines the mapped columns of the “weak/dominated” side of the relationship.

Let us add some data to the database. I will post bellow the code that will create a relationship between the Customer and Dog (if you want to execute the code bellow, check the older posts about JPA listed in the beginning of this post):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class Main {
    public static void main(String[] args) {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("Hello");
        EntityManager em = emf.createEntityManager();
        try {
            em.getTransaction().begin();
            List dogs = new ArrayList();
            dogs.add(new Dog("Terminator"));
            dogs.add(new Dog("Fluffy"));
            dogs.add(new Dog("Bacon"));
            Customer customer = new Customer();
            customer.setName("Arnold");
            customer.setDogs(dogs);
            em.persist(customer);
            em.getTransaction().commit();
        }
        catch (Exception e) {
            em.getTransaction().rollback();
            e.printStackTrace();
        }
        finally{
            emf.close();
        }
        System.out.println("It is over");
    }
}

Take a look at the results:

Console Image.

Database’s Image.

The JPA found the next sequence value to each object, inserted the objects and then inserted the relationship into the “CUSTOMER_HAS_DOGS”.

To use the @OneToMany annotation without an extra table, we can use the @JoinColumn annotation instead using the @JoinTable. Check out how our Customer class will look like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com;
import java.util.List;
//Using the * to make the import list smaller
import javax.persistence.*;
@Entity
@Table(name = "CUSTOMER")
@SequenceGenerator(name = "CUSTOMER_SEQUENCE", sequenceName = "CUSTOMER_SEQUENCE", allocationSize = 1, initialValue = 0)
public class Customer {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "CUSTOMER_SEQUENCE")
    private int id;
    @Column
    private String name;
    @OneToOne(cascade = CascadeType.ALL, optional = true, fetch = FetchType.EAGER, orphanRemoval = true)
    @JoinColumn(name="USER_ID", nullable=true)
    private User user;
    @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
    @JoinColumn(name="CUSTOMER_ID")
    private List dogs;
    //Getters and Setters
}

The @JoinColumn indicates which column will be used as the ID.

Delete the database Schema and create it again. Run the Main class again and check out the final result:

Console Image.

Database’s Image.

Notice that there is no need of another table in the system to do the relationship. In the Dog table, a new column was created to store this value.

To transform this Unidirectional relationship into a Bidirectional relationship, let us change our Dog class:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com;
//Using the * to make the import list smaller
import javax.persistence.*;
@Entity
@Table(name="DOG")
@SequenceGenerator(name="DOG_SEQUENCE", sequenceName="DOG_SEQUENCE", allocationSize=1, initialValue=0)
public class Dog {
    public Dog(){
    }
    public Dog(String name){
        this.name = name;
    }
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="DOG_SEQUENCE")
    private int id;
    @Column
    private String name;
    @ManyToOne(cascade=CascadeType.ALL)
    private Customer owner;   
    //Getters and Setters
}

If you still with doubts about the concepts of Unidirectional and Bidirectional relationships, you can find the explanation here: JPA @OneToOne Unidirectional and Bidirectional.

By default, the annotation @ManyToOne is the one that should be the owner in a relationship with @OneToMany. If you check the @ManyToOne annotation API you will not find the “mappedBy” as parameter.

If you want to practice more, you could pass all the parameters of the @OneToMany (Customer class) to the @ManyToOne (Dog class), and put in the @OneToMany the “mappedBy” parameter.

I hope that you enjoyed this post.

Doubts/Suggestions just post it.

See you soon.